diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index 5e71b2d..f998bd6 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -10,10 +10,14 @@ #include <_stdio.h> uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; -char format = 0x0F; +uint8_t format = 0x0A; -void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { - *(framebuffer + position) = c; +void setTextStyle(uint8_t style) { + format = style; +} + +void putCharWithFormatAtOffset(uint16_t c, uint16_t offset) { + *(framebuffer + offset) = c; } void putCharWithFormatAtPosition(uint8_t x, uint8_t y, uint32_t c) { @@ -21,7 +25,7 @@ } void putCharAtOffset(char c, uint16_t offset) { - putCharWithFormatAtOffset(c | format << 8, offset); + putCharWithFormatAtOffset((uint16_t) c | (uint16_t) format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { @@ -71,6 +75,9 @@ newLine(); return; } + if (c == 0x00) { + return; + } uint16_t offset = getCursorOffset(); putCharAtOffset(c, offset); setCursorOffset(offset + 1); @@ -86,6 +93,13 @@ char HEX_CHARS[] = "0123456789ABCDEF"; void putHex(char** write, uint32_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } bool alreadyWriting = false; for (int position = 3; position >= 0; position--) { uint8_t byte = (x >> (position * 8)) & 0xFF; @@ -93,7 +107,7 @@ alreadyWriting = true; } if (alreadyWriting) { - **write = HEX_CHARS[byte >> 8]; + **write = HEX_CHARS[byte >> 4]; (*write)++; **write = HEX_CHARS[byte & 0x0F]; (*write)++; @@ -189,10 +203,6 @@ } } -void setTextStyle(uint8_t style) { - format = style; -} - void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { if (string[i] == '\n') { diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index 5e71b2d..f998bd6 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -10,10 +10,14 @@ #include <_stdio.h> uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; -char format = 0x0F; +uint8_t format = 0x0A; -void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { - *(framebuffer + position) = c; +void setTextStyle(uint8_t style) { + format = style; +} + +void putCharWithFormatAtOffset(uint16_t c, uint16_t offset) { + *(framebuffer + offset) = c; } void putCharWithFormatAtPosition(uint8_t x, uint8_t y, uint32_t c) { @@ -21,7 +25,7 @@ } void putCharAtOffset(char c, uint16_t offset) { - putCharWithFormatAtOffset(c | format << 8, offset); + putCharWithFormatAtOffset((uint16_t) c | (uint16_t) format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { @@ -71,6 +75,9 @@ newLine(); return; } + if (c == 0x00) { + return; + } uint16_t offset = getCursorOffset(); putCharAtOffset(c, offset); setCursorOffset(offset + 1); @@ -86,6 +93,13 @@ char HEX_CHARS[] = "0123456789ABCDEF"; void putHex(char** write, uint32_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } bool alreadyWriting = false; for (int position = 3; position >= 0; position--) { uint8_t byte = (x >> (position * 8)) & 0xFF; @@ -93,7 +107,7 @@ alreadyWriting = true; } if (alreadyWriting) { - **write = HEX_CHARS[byte >> 8]; + **write = HEX_CHARS[byte >> 4]; (*write)++; **write = HEX_CHARS[byte & 0x0F]; (*write)++; @@ -189,10 +203,6 @@ } } -void setTextStyle(uint8_t style) { - format = style; -} - void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { if (string[i] == '\n') { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 75f4624..b442fac 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include extern uint32_t _kernel_end; @@ -15,9 +17,8 @@ initOSTasks(); drawLogo(); printf("initializing interrupts\n"); + setupDevices(); initInterrupts(); yields(); - setupTimer(); while(1); - yield(); } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index 5e71b2d..f998bd6 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -10,10 +10,14 @@ #include <_stdio.h> uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; -char format = 0x0F; +uint8_t format = 0x0A; -void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { - *(framebuffer + position) = c; +void setTextStyle(uint8_t style) { + format = style; +} + +void putCharWithFormatAtOffset(uint16_t c, uint16_t offset) { + *(framebuffer + offset) = c; } void putCharWithFormatAtPosition(uint8_t x, uint8_t y, uint32_t c) { @@ -21,7 +25,7 @@ } void putCharAtOffset(char c, uint16_t offset) { - putCharWithFormatAtOffset(c | format << 8, offset); + putCharWithFormatAtOffset((uint16_t) c | (uint16_t) format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { @@ -71,6 +75,9 @@ newLine(); return; } + if (c == 0x00) { + return; + } uint16_t offset = getCursorOffset(); putCharAtOffset(c, offset); setCursorOffset(offset + 1); @@ -86,6 +93,13 @@ char HEX_CHARS[] = "0123456789ABCDEF"; void putHex(char** write, uint32_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } bool alreadyWriting = false; for (int position = 3; position >= 0; position--) { uint8_t byte = (x >> (position * 8)) & 0xFF; @@ -93,7 +107,7 @@ alreadyWriting = true; } if (alreadyWriting) { - **write = HEX_CHARS[byte >> 8]; + **write = HEX_CHARS[byte >> 4]; (*write)++; **write = HEX_CHARS[byte & 0x0F]; (*write)++; @@ -189,10 +203,6 @@ } } -void setTextStyle(uint8_t style) { - format = style; -} - void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { if (string[i] == '\n') { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 75f4624..b442fac 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include extern uint32_t _kernel_end; @@ -15,9 +17,8 @@ initOSTasks(); drawLogo(); printf("initializing interrupts\n"); + setupDevices(); initInterrupts(); yields(); - setupTimer(); while(1); - yield(); } \ No newline at end of file diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 5d52a79..adf2dba 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -9,7 +9,6 @@ void printLoop() { clearScreen(); - setTextStyle(0x0F); while (1) { Message* message = popMessage(&printerTask); if (message == 0) { diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index 5e71b2d..f998bd6 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -10,10 +10,14 @@ #include <_stdio.h> uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; -char format = 0x0F; +uint8_t format = 0x0A; -void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { - *(framebuffer + position) = c; +void setTextStyle(uint8_t style) { + format = style; +} + +void putCharWithFormatAtOffset(uint16_t c, uint16_t offset) { + *(framebuffer + offset) = c; } void putCharWithFormatAtPosition(uint8_t x, uint8_t y, uint32_t c) { @@ -21,7 +25,7 @@ } void putCharAtOffset(char c, uint16_t offset) { - putCharWithFormatAtOffset(c | format << 8, offset); + putCharWithFormatAtOffset((uint16_t) c | (uint16_t) format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { @@ -71,6 +75,9 @@ newLine(); return; } + if (c == 0x00) { + return; + } uint16_t offset = getCursorOffset(); putCharAtOffset(c, offset); setCursorOffset(offset + 1); @@ -86,6 +93,13 @@ char HEX_CHARS[] = "0123456789ABCDEF"; void putHex(char** write, uint32_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } bool alreadyWriting = false; for (int position = 3; position >= 0; position--) { uint8_t byte = (x >> (position * 8)) & 0xFF; @@ -93,7 +107,7 @@ alreadyWriting = true; } if (alreadyWriting) { - **write = HEX_CHARS[byte >> 8]; + **write = HEX_CHARS[byte >> 4]; (*write)++; **write = HEX_CHARS[byte & 0x0F]; (*write)++; @@ -189,10 +203,6 @@ } } -void setTextStyle(uint8_t style) { - format = style; -} - void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { if (string[i] == '\n') { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 75f4624..b442fac 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include extern uint32_t _kernel_end; @@ -15,9 +17,8 @@ initOSTasks(); drawLogo(); printf("initializing interrupts\n"); + setupDevices(); initInterrupts(); yields(); - setupTimer(); while(1); - yield(); } \ No newline at end of file diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 5d52a79..adf2dba 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -9,7 +9,6 @@ void printLoop() { clearScreen(); - setTextStyle(0x0F); while (1) { Message* message = popMessage(&printerTask); if (message == 0) { diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 4b93d2d..3964e7c 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -2,7 +2,7 @@ #include #include <_stdio.h> -#define STACK_SIZE 0x1000 +#define STACK_SIZE 0x100000 Task *currentTask; @@ -26,8 +26,8 @@ Task* last = currentTask; currentTask = last->nextTask; if (currentTask == 0x00) { - puts("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1); + return; } last->nextTask = 0x00; switchTask(&(last->registers), &(currentTask->registers)); @@ -35,6 +35,11 @@ void schedule(Task* task) { Task* test = currentTask; + if (currentTask == 0x00) { + currentTask = task; + currentTask->nextTask = 0x00; + return; + } while (test->nextTask != 0x0) { if (test->nextTask == task) { return; // don't schedule if the task is already in the queue diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index 5e71b2d..f998bd6 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -10,10 +10,14 @@ #include <_stdio.h> uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; -char format = 0x0F; +uint8_t format = 0x0A; -void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { - *(framebuffer + position) = c; +void setTextStyle(uint8_t style) { + format = style; +} + +void putCharWithFormatAtOffset(uint16_t c, uint16_t offset) { + *(framebuffer + offset) = c; } void putCharWithFormatAtPosition(uint8_t x, uint8_t y, uint32_t c) { @@ -21,7 +25,7 @@ } void putCharAtOffset(char c, uint16_t offset) { - putCharWithFormatAtOffset(c | format << 8, offset); + putCharWithFormatAtOffset((uint16_t) c | (uint16_t) format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { @@ -71,6 +75,9 @@ newLine(); return; } + if (c == 0x00) { + return; + } uint16_t offset = getCursorOffset(); putCharAtOffset(c, offset); setCursorOffset(offset + 1); @@ -86,6 +93,13 @@ char HEX_CHARS[] = "0123456789ABCDEF"; void putHex(char** write, uint32_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } bool alreadyWriting = false; for (int position = 3; position >= 0; position--) { uint8_t byte = (x >> (position * 8)) & 0xFF; @@ -93,7 +107,7 @@ alreadyWriting = true; } if (alreadyWriting) { - **write = HEX_CHARS[byte >> 8]; + **write = HEX_CHARS[byte >> 4]; (*write)++; **write = HEX_CHARS[byte & 0x0F]; (*write)++; @@ -189,10 +203,6 @@ } } -void setTextStyle(uint8_t style) { - format = style; -} - void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { if (string[i] == '\n') { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 75f4624..b442fac 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include extern uint32_t _kernel_end; @@ -15,9 +17,8 @@ initOSTasks(); drawLogo(); printf("initializing interrupts\n"); + setupDevices(); initInterrupts(); yields(); - setupTimer(); while(1); - yield(); } \ No newline at end of file diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 5d52a79..adf2dba 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -9,7 +9,6 @@ void printLoop() { clearScreen(); - setTextStyle(0x0F); while (1) { Message* message = popMessage(&printerTask); if (message == 0) { diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 4b93d2d..3964e7c 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -2,7 +2,7 @@ #include #include <_stdio.h> -#define STACK_SIZE 0x1000 +#define STACK_SIZE 0x100000 Task *currentTask; @@ -26,8 +26,8 @@ Task* last = currentTask; currentTask = last->nextTask; if (currentTask == 0x00) { - puts("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1); + return; } last->nextTask = 0x00; switchTask(&(last->registers), &(currentTask->registers)); @@ -35,6 +35,11 @@ void schedule(Task* task) { Task* test = currentTask; + if (currentTask == 0x00) { + currentTask = task; + currentTask->nextTask = 0x00; + return; + } while (test->nextTask != 0x0) { if (test->nextTask == task) { return; // don't schedule if the task is already in the queue diff --git a/src/kernel/util/tree-os.c b/src/kernel/util/tree-os.c index 681c1e0..bb4c71c 100644 --- a/src/kernel/util/tree-os.c +++ b/src/kernel/util/tree-os.c @@ -1,5 +1,6 @@ #include #include <_stdio.h> +#include const char* logo = "\ _______ \n\ @@ -12,4 +13,6 @@ void drawLogo() { printf(logo); printf("TREE-OS v. alpha 0.1 (IN DEVELOPMENT)\n\n"); + yields(); + setTextStyle(0x0F); } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index e94ea84..d8219bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "array": "c", "string_view": "c", "initializer_list": "c", - "utility": "c" + "utility": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 0a31a7a..0b66ce3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = i686-elf-gcc -CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/headers +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include LD = i686-elf-ld LD_FLAGS = -z max-page-size=0x1000 -T linker.ld AS = nasm diff --git a/src/headers/_stdio.h b/src/headers/_stdio.h deleted file mode 100644 index b5d4f87..0000000 --- a/src/headers/_stdio.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include - -#define FRAMEBUFFER_LOCATION 0x000B8000 -#define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 25 - -extern void setTextStyle(uint8_t style); -extern void clearScreen(); -extern void printf(const char* format, ...); -extern void putCharAt(char c, uint8_t x, uint8_t y); -extern void putCharsAt(char* string, uint8_t x, uint8_t y); -extern void puts(char* string); -extern void putChars(char* string, uint32_t length); - -extern uint32_t strlen(char* string); - -#endif \ No newline at end of file diff --git a/src/headers/alloc.h b/src/headers/alloc.h deleted file mode 100644 index 82023d4..0000000 --- a/src/headers/alloc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ALLOC_H -#define ALLOC_H - -#include -#include - -typedef enum MemoryState { - FREE = 0, - IN_USE = 1 -} MemoryState; - -typedef struct MemoryBlock { - struct MemoryBlock* last; - struct MemoryBlock* next; - MemoryState state; - uint32_t size; - Task* task; -} MemoryBlock; - -extern void initMemoryAllocation(uint32_t kernelEnd); -extern void* malloc(uint32_t size); -extern void* mallocTask(uint32_t size, Task* task); -extern void free(void* location); -extern void printMemoryStack(); -extern void freeTaskAllocations(Task* task); -extern Task* getCurrentTask(); - -#endif \ No newline at end of file diff --git a/src/headers/cursor.h b/src/headers/cursor.h deleted file mode 100644 index 30f91c1..0000000 --- a/src/headers/cursor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CURSOR_H -#define CURSOR_H - -#include - -extern void setCursorOffset(uint16_t offset); -extern void setCursorPosition(uint8_t x, uint8_t y); -extern uint16_t getCursorOffset(); - -#endif \ No newline at end of file diff --git a/src/headers/exceptions.h b/src/headers/exceptions.h deleted file mode 100644 index 8990d35..0000000 --- a/src/headers/exceptions.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H - -extern void setupExceptions(); - -extern void isrHandler0(); -extern void isrHandler1(); -extern void isrHandler2(); -extern void isrHandler3(); -extern void isrHandler4(); -extern void isrHandler5(); -extern void isrHandler6(); -extern void isrHandler7(); -extern void isrHandler8(); -extern void isrHandler9(); -extern void isrHandler10(); -extern void isrHandler11(); -extern void isrHandler12(); -extern void isrHandler13(); -extern void isrHandler14(); -extern void isrHandler15(); -extern void isrHandler16(); -extern void isrHandler17(); -extern void isrHandler18(); -extern void isrHandler19(); -extern void isrHandler20(); -extern void isrHandler21(); -extern void isrHandler22(); -extern void isrHandler23(); -extern void isrHandler24(); -extern void isrHandler25(); -extern void isrHandler26(); -extern void isrHandler27(); -extern void isrHandler28(); -extern void isrHandler29(); -extern void isrHandler30(); -extern void isrHandler31(); - -#endif \ No newline at end of file diff --git a/src/headers/interrupts.h b/src/headers/interrupts.h deleted file mode 100644 index f8ed10a..0000000 --- a/src/headers/interrupts.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef INTERRUPTS_H -#define INTERRUPTS_H - -#include - -typedef struct { - uint16_t isr_low; - uint16_t codeSegment; - uint8_t reserved; - uint8_t attributes; - uint16_t isr_high; -} __attribute__((packed)) IDTEntry; - -typedef struct { - uint16_t limit; - uint32_t base; -} __attribute__((packed)) IDTR; - -typedef struct { - unsigned int gs, fs, es, ds; - unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; - unsigned int int_no, err_code; - unsigned int eip, cs, eflags, useresp, ss; -} __attribute__((packed)) regs; - -extern void initInterrupts(); -extern void setInterrupt(uint8_t vector, void* callback); - -#endif \ No newline at end of file diff --git a/src/headers/irqs.h b/src/headers/irqs.h deleted file mode 100644 index c3cde17..0000000 --- a/src/headers/irqs.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef IRQS_H -#define IRQS_H - -#include - -extern void initIRQs(); - -extern void setIRQHandler(uint8_t irqNumber, void* fun); - -extern void irqHandler0(); -extern void irqHandler1(); -extern void irqHandler2(); -extern void irqHandler3(); -extern void irqHandler4(); -extern void irqHandler5(); -extern void irqHandler6(); -extern void irqHandler7(); -extern void irqHandler8(); -extern void irqHandler9(); -extern void irqHandler10(); -extern void irqHandler11(); -extern void irqHandler12(); -extern void irqHandler13(); -extern void irqHandler14(); -extern void irqHandler15(); - -#endif \ No newline at end of file diff --git a/src/headers/message.h b/src/headers/message.h deleted file mode 100644 index 2f8ddbe..0000000 --- a/src/headers/message.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -#include - -typedef struct Message { - void* data; - uint32_t size; - struct Message* next; -} Message; - -#endif \ No newline at end of file diff --git a/src/headers/osTasks.h b/src/headers/osTasks.h deleted file mode 100644 index 2865863..0000000 --- a/src/headers/osTasks.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef OS_TASKS_H -#define OS_TASKS_H - -#include - -extern void initOSTasks(); - -extern Task* getPrinterTask(); - -#endif \ No newline at end of file diff --git a/src/headers/ports.h b/src/headers/ports.h deleted file mode 100644 index a47812e..0000000 --- a/src/headers/ports.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PORTS_H -#define PORTS_H - -#include - -extern void outb(uint16_t port, uint8_t val); -extern uint8_t inb(uint16_t port); - -extern void ioWait(); - -#endif \ No newline at end of file diff --git a/src/headers/task.h b/src/headers/task.h deleted file mode 100644 index 0b8e1b4..0000000 --- a/src/headers/task.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TASK_H -#define TASK_H - -#include -#include - -extern void initTasking(); - -typedef struct __attribute__ ((packed)) { - uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; -} Registers; - -typedef struct Task { - Registers registers; // the register states for the task - struct Task *nextTask; // linked list of tasks that need to be done - void* stack; - Message* message; -} Task; - -extern void initTasking(); -extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); - -extern void yield(); -extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); // schedule a task to be run in the future -extern void destroyCurrentTask(); - -extern void setRunningTask(Task* task); // set the task currently executed -extern void sendMessage(Task* task, Message* message); - -extern Message* popMessage(Task* task); - -#endif \ No newline at end of file diff --git a/src/headers/timer.h b/src/headers/timer.h deleted file mode 100644 index e977777..0000000 --- a/src/headers/timer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIMER_H -#define TIMER_H - -extern void setupTimer(); - -#endif \ No newline at end of file diff --git a/src/headers/tree-os.h b/src/headers/tree-os.h deleted file mode 100644 index 71476fe..0000000 --- a/src/headers/tree-os.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TREE_OS_H -#define TREE_OS_H - -extern void drawLogo(); - -#endif \ No newline at end of file diff --git a/src/include/_stdio.h b/src/include/_stdio.h new file mode 100644 index 0000000..1fbe95a --- /dev/null +++ b/src/include/_stdio.h @@ -0,0 +1,21 @@ +#ifndef STDIO_H +#define STDIO_H + +#include + +#define FRAMEBUFFER_LOCATION 0x000B8000 +#define VIDEO_WIDTH 80 +#define VIDEO_HEIGHT 25 + +extern void setTextStyle(uint8_t style); +extern void clearScreen(); +extern void printf(const char* format, ...); +extern void putCharAt(char c, uint8_t x, uint8_t y); +extern void putCharsAt(char* string, uint8_t x, uint8_t y); +extern void puts(char* string); +extern void putChars(char* string, uint32_t length); +extern void putChar(char c); + +extern uint32_t strlen(char* string); + +#endif \ No newline at end of file diff --git a/src/include/alloc.h b/src/include/alloc.h new file mode 100644 index 0000000..82023d4 --- /dev/null +++ b/src/include/alloc.h @@ -0,0 +1,28 @@ +#ifndef ALLOC_H +#define ALLOC_H + +#include +#include + +typedef enum MemoryState { + FREE = 0, + IN_USE = 1 +} MemoryState; + +typedef struct MemoryBlock { + struct MemoryBlock* last; + struct MemoryBlock* next; + MemoryState state; + uint32_t size; + Task* task; +} MemoryBlock; + +extern void initMemoryAllocation(uint32_t kernelEnd); +extern void* malloc(uint32_t size); +extern void* mallocTask(uint32_t size, Task* task); +extern void free(void* location); +extern void printMemoryStack(); +extern void freeTaskAllocations(Task* task); +extern Task* getCurrentTask(); + +#endif \ No newline at end of file diff --git a/src/include/cursor.h b/src/include/cursor.h new file mode 100644 index 0000000..30f91c1 --- /dev/null +++ b/src/include/cursor.h @@ -0,0 +1,10 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include + +extern void setCursorOffset(uint16_t offset); +extern void setCursorPosition(uint8_t x, uint8_t y); +extern uint16_t getCursorOffset(); + +#endif \ No newline at end of file diff --git a/src/include/devices.h b/src/include/devices.h new file mode 100644 index 0000000..ddc6581 --- /dev/null +++ b/src/include/devices.h @@ -0,0 +1,6 @@ +#ifndef DEVICES_H +#define DEVICES_H + +extern void setupDevices(); + +#endif \ No newline at end of file diff --git a/src/include/exceptions.h b/src/include/exceptions.h new file mode 100644 index 0000000..8990d35 --- /dev/null +++ b/src/include/exceptions.h @@ -0,0 +1,39 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +extern void setupExceptions(); + +extern void isrHandler0(); +extern void isrHandler1(); +extern void isrHandler2(); +extern void isrHandler3(); +extern void isrHandler4(); +extern void isrHandler5(); +extern void isrHandler6(); +extern void isrHandler7(); +extern void isrHandler8(); +extern void isrHandler9(); +extern void isrHandler10(); +extern void isrHandler11(); +extern void isrHandler12(); +extern void isrHandler13(); +extern void isrHandler14(); +extern void isrHandler15(); +extern void isrHandler16(); +extern void isrHandler17(); +extern void isrHandler18(); +extern void isrHandler19(); +extern void isrHandler20(); +extern void isrHandler21(); +extern void isrHandler22(); +extern void isrHandler23(); +extern void isrHandler24(); +extern void isrHandler25(); +extern void isrHandler26(); +extern void isrHandler27(); +extern void isrHandler28(); +extern void isrHandler29(); +extern void isrHandler30(); +extern void isrHandler31(); + +#endif \ No newline at end of file diff --git a/src/include/interrupts.h b/src/include/interrupts.h new file mode 100644 index 0000000..f8ed10a --- /dev/null +++ b/src/include/interrupts.h @@ -0,0 +1,29 @@ +#ifndef INTERRUPTS_H +#define INTERRUPTS_H + +#include + +typedef struct { + uint16_t isr_low; + uint16_t codeSegment; + uint8_t reserved; + uint8_t attributes; + uint16_t isr_high; +} __attribute__((packed)) IDTEntry; + +typedef struct { + uint16_t limit; + uint32_t base; +} __attribute__((packed)) IDTR; + +typedef struct { + unsigned int gs, fs, es, ds; + unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; + unsigned int int_no, err_code; + unsigned int eip, cs, eflags, useresp, ss; +} __attribute__((packed)) regs; + +extern void initInterrupts(); +extern void setInterrupt(uint8_t vector, void* callback); + +#endif \ No newline at end of file diff --git a/src/include/irqs.h b/src/include/irqs.h new file mode 100644 index 0000000..a859ab4 --- /dev/null +++ b/src/include/irqs.h @@ -0,0 +1,27 @@ +#ifndef IRQS_H +#define IRQS_H + +#include + +extern void setupIRQs(); + +extern void setIRQHandler(uint8_t irqNumber, void* fun); + +extern void irqHandler0(); +extern void irqHandler1(); +extern void irqHandler2(); +extern void irqHandler3(); +extern void irqHandler4(); +extern void irqHandler5(); +extern void irqHandler6(); +extern void irqHandler7(); +extern void irqHandler8(); +extern void irqHandler9(); +extern void irqHandler10(); +extern void irqHandler11(); +extern void irqHandler12(); +extern void irqHandler13(); +extern void irqHandler14(); +extern void irqHandler15(); + +#endif \ No newline at end of file diff --git a/src/include/keyboard.h b/src/include/keyboard.h new file mode 100644 index 0000000..d9e64b8 --- /dev/null +++ b/src/include/keyboard.h @@ -0,0 +1,6 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +extern void setupKeyboard(); + +#endif \ No newline at end of file diff --git a/src/include/message.h b/src/include/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/include/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/include/osTasks.h b/src/include/osTasks.h new file mode 100644 index 0000000..2865863 --- /dev/null +++ b/src/include/osTasks.h @@ -0,0 +1,10 @@ +#ifndef OS_TASKS_H +#define OS_TASKS_H + +#include + +extern void initOSTasks(); + +extern Task* getPrinterTask(); + +#endif \ No newline at end of file diff --git a/src/include/ports.h b/src/include/ports.h new file mode 100644 index 0000000..a47812e --- /dev/null +++ b/src/include/ports.h @@ -0,0 +1,11 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +extern void outb(uint16_t port, uint8_t val); +extern uint8_t inb(uint16_t port); + +extern void ioWait(); + +#endif \ No newline at end of file diff --git a/src/include/task.h b/src/include/task.h new file mode 100644 index 0000000..0b8e1b4 --- /dev/null +++ b/src/include/task.h @@ -0,0 +1,34 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include + +extern void initTasking(); + +typedef struct __attribute__ ((packed)) { + uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3; +} Registers; + +typedef struct Task { + Registers registers; // the register states for the task + struct Task *nextTask; // linked list of tasks that need to be done + void* stack; + Message* message; +} Task; + +extern void initTasking(); +extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); + +extern void yield(); +extern void yields(); // yield, but schedule the currently running task +extern void switchTask(Registers *old, Registers *new); +extern void schedule(Task* task); // schedule a task to be run in the future +extern void destroyCurrentTask(); + +extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); + +#endif \ No newline at end of file diff --git a/src/include/timer.h b/src/include/timer.h new file mode 100644 index 0000000..e977777 --- /dev/null +++ b/src/include/timer.h @@ -0,0 +1,6 @@ +#ifndef TIMER_H +#define TIMER_H + +extern void setupTimer(); + +#endif \ No newline at end of file diff --git a/src/include/tree-os.h b/src/include/tree-os.h new file mode 100644 index 0000000..71476fe --- /dev/null +++ b/src/include/tree-os.h @@ -0,0 +1,6 @@ +#ifndef TREE_OS_H +#define TREE_OS_H + +extern void drawLogo(); + +#endif \ No newline at end of file diff --git a/src/interrupts/exceptions.asm b/src/interrupts/exceptions.asm deleted file mode 100644 index 9fd4f04..0000000 --- a/src/interrupts/exceptions.asm +++ /dev/null @@ -1,74 +0,0 @@ -%macro isr 1 - global isrHandler%1 - isrHandler%1: - push byte 0 - push byte %1 - jmp exceptionHandler -%endmacro - -%macro isr_error 1 - global isrHandler%1 - isrHandler%1: - push byte %1 - jmp exceptionHandler -%endmacro - -isrs: - isr 0 - isr 1 - isr 2 - isr 3 - isr 4 - isr 5 - isr 6 - isr 7 - isr_error 8 - isr 9 - isr_error 10 - isr_error 11 - isr_error 12 - isr_error 13 - isr_error 14 - isr 15 - isr 16 - isr_error 17 - isr 18 - isr 19 - isr 20 - isr 21 - isr 22 - isr 23 - isr 24 - isr 25 - isr 26 - isr 27 - isr 28 - isr 29 - isr_error 30 - isr 31 - -extern handleException - -exceptionHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleException - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/exceptions.c b/src/interrupts/exceptions.c deleted file mode 100644 index 8d82af9..0000000 --- a/src/interrupts/exceptions.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include <_stdio.h> - -char* EXCEPTION_MESSAGES[] = { - "DIVIDE BY ZERO", - "DEBUG", - "NON-MASKABLE INTERRUPT", - "BREAKPOINT", - "OVERFLOW", - "BOUND RAGE EXCEEDED", - "INVALID OPCODE", - "DEVICE NOT AVAILABLE", - "DOUBLE FAULT", - "COPROCESSOR SEGMENT OVERRUN", - "INVALID TSS", - "SEGMENT NOT PRESENT", - "STACK SEGMENT FAULT", - "GENERAL PROTECTION FAULT", - "PAGE FAULT", - "RESERVED", - "x87 FLOATING-POINT-EXCEPTION", - "ALIGNMENT CHECK", - "MACHINE CHECK", - "SMID FLOATING-POINT-EXCEPTION", - "VIRTUALIZATION EXCEPTION", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "RESERVED", - "SECURITY EXCEPTION", - "RESERVED" -}; - -void setupExceptions() { - printf("setting exceptions\n"); - setInterrupt(0, &isrHandler0); - setInterrupt(1, &isrHandler1); - setInterrupt(2, &isrHandler2); - setInterrupt(3, &isrHandler3); - setInterrupt(4, &isrHandler4); - setInterrupt(5, &isrHandler5); - setInterrupt(6, &isrHandler6); - setInterrupt(7, &isrHandler7); - setInterrupt(8, &isrHandler8); - setInterrupt(9, &isrHandler9); - setInterrupt(10, &isrHandler10); - setInterrupt(11, &isrHandler11); - setInterrupt(12, &isrHandler12); - setInterrupt(13, &isrHandler13); - setInterrupt(14, &isrHandler14); - setInterrupt(15, &isrHandler15); - setInterrupt(16, &isrHandler16); - setInterrupt(17, &isrHandler17); - setInterrupt(18, &isrHandler18); - setInterrupt(19, &isrHandler19); - setInterrupt(20, &isrHandler20); - setInterrupt(21, &isrHandler21); - setInterrupt(22, &isrHandler22); - setInterrupt(23, &isrHandler23); - setInterrupt(24, &isrHandler24); - setInterrupt(25, &isrHandler25); - setInterrupt(26, &isrHandler26); - setInterrupt(27, &isrHandler27); - setInterrupt(28, &isrHandler28); - setInterrupt(29, &isrHandler29); - setInterrupt(30, &isrHandler30); - setInterrupt(31, &isrHandler31); -} - -void handleException(regs* registers) { - printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/interrupts.c b/src/interrupts/interrupts.c deleted file mode 100644 index 908e4ef..0000000 --- a/src/interrupts/interrupts.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include -#include - -IDTR idtr; -IDTEntry* entries; -void* buffer; - -void setInterrupt(uint8_t vector, void* callback) { - IDTEntry* descriptor = &entries[vector]; - descriptor->isr_low = (uint32_t)callback & 0xFFFF; - descriptor->codeSegment = 0x08; - descriptor->attributes = 0x8E; - descriptor->isr_high = (uint32_t)callback >> 16; - descriptor->reserved = 0; -} - - -void initInterrupts() { - buffer = malloc(sizeof(IDTEntry) * 257); - entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); - idtr.limit = sizeof(IDTEntry) * 256 - 1; - idtr.base = (uint32_t) entries; - setupExceptions(); - setupIRQs(); - __asm__ volatile ("lidt %0" : : "memory"(idtr)); - __asm__ volatile ("sti"); -} \ No newline at end of file diff --git a/src/interrupts/irqs.asm b/src/interrupts/irqs.asm deleted file mode 100644 index 3e6670b..0000000 --- a/src/interrupts/irqs.asm +++ /dev/null @@ -1,52 +0,0 @@ -%macro irq 1 - global irqHandler%1 - irqHandler%1: - cli - push byte 0 - push byte %1+32 - jmp irqHandler -%endmacro - -irqs: - irq 0 - irq 1 - irq 2 - irq 3 - irq 4 - irq 5 - irq 6 - irq 7 - irq 8 - irq 9 - irq 10 - irq 11 - irq 12 - irq 13 - irq 14 - irq 15 - -extern handleIRQ - -irqHandler: - pusha - push ds - push es - push fs - push gs - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov eax, esp - push eax - mov eax, handleIRQ - call eax - pop eax - pop gs - pop fs - pop es - pop ds - popa - add esp, 8 - iret \ No newline at end of file diff --git a/src/interrupts/irqs.c b/src/interrupts/irqs.c deleted file mode 100644 index 65826ac..0000000 --- a/src/interrupts/irqs.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include <_stdio.h> - -#define OFFSET_1 32 -#define OFFSET_2 40 - -void remapPIC(int offset1, int offset2) { - printf("remapping pic\n"); - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, offset1); - outb(0x21, offset2); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -void setupIRQs() { - printf("setting IRQs\n"); - setInterrupt(OFFSET_1 + 0, &irqHandler0); - setInterrupt(OFFSET_1 + 1, &irqHandler1); - setInterrupt(OFFSET_1 + 2, &irqHandler2); - setInterrupt(OFFSET_1 + 3, &irqHandler3); - setInterrupt(OFFSET_1 + 4, &irqHandler4); - setInterrupt(OFFSET_1 + 5, &irqHandler5); - setInterrupt(OFFSET_1 + 6, &irqHandler6); - setInterrupt(OFFSET_1 + 7, &irqHandler7); - setInterrupt(OFFSET_2 + 0, &irqHandler8); - setInterrupt(OFFSET_2 + 1, &irqHandler9); - setInterrupt(OFFSET_2 + 2, &irqHandler10); - setInterrupt(OFFSET_2 + 3, &irqHandler11); - setInterrupt(OFFSET_2 + 4, &irqHandler12); - setInterrupt(OFFSET_2 + 5, &irqHandler13); - setInterrupt(OFFSET_2 + 6, &irqHandler14); - setInterrupt(OFFSET_2 + 7, &irqHandler15); - remapPIC(OFFSET_1, OFFSET_2); -} - -void* irqHandlers[16]; - -void setIRQHandler(uint8_t irqNumber, void* fun) { - irqHandlers[irqNumber] = fun; -} - -void handleIRQ(regs* registers) { - if (registers->int_no >= OFFSET_2) { - outb(0xA0, 0x20); - } - outb(0x20, 0x20); - void (*handler)() = irqHandlers[registers->int_no - OFFSET_1]; - if (handler) { - handler(); - return; - } - printf("unhandeled IRQ no. 0x%x was triggered!\n", registers->int_no); - yields(); -} \ No newline at end of file diff --git a/src/interrupts/timer/timer.c b/src/interrupts/timer/timer.c deleted file mode 100644 index 440118a..0000000 --- a/src/interrupts/timer/timer.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include <_stdio.h> -#include -#include -#include -#include - - -#define PIT_A 0x40 -#define PIT_CONTROL 0x43 - -#define PIT_MASK 0xFF -#define PIT_SCALE 1193180 -#define PIT_SET 0x36 - -#define CMD_BINARY 0x00 - -#define CMD_MODE0 0x00 -#define CMD_MODE1 0x02 -#define CMD_MODE2 0x04 -#define CMD_MODE3 0x06 -#define CMD_MODE4 0x08 -#define CMD_MODE5 0x0a - -#define CMD_RW_BOTH 0x30 - -#define CMD_COUNTER0 0x00 -#define CMD_COUNTER2 0x80 - -void setTimerFreq(uint32_t hz) { - int divisor = PIT_SCALE / hz; - outb(PIT_CONTROL, 0x36);// CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); - outb(PIT_A, (uint8_t) divisor); - outb(PIT_A, (uint8_t) (divisor >> 8)); -} - -uint32_t timer_ticks = 0; - -void timerHandler() { - printf("timer 0x%x\n", timer_ticks); - timer_ticks++; - yields(); -} - -void setupTimer() { - printf("setting timer frequency to 100Hz\n"); - setTimerFreq(20); - setIRQHandler(0, &timerHandler); -} diff --git a/src/kernel/drivers/devices.c b/src/kernel/drivers/devices.c new file mode 100644 index 0000000..d4638a7 --- /dev/null +++ b/src/kernel/drivers/devices.c @@ -0,0 +1,8 @@ +#include +#include +#include + +void setupDevices() { + setupTimer(); + setupKeyboard(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.asm b/src/kernel/drivers/interrupts/exceptions.asm new file mode 100644 index 0000000..9fd4f04 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.asm @@ -0,0 +1,74 @@ +%macro isr 1 + global isrHandler%1 + isrHandler%1: + push byte 0 + push byte %1 + jmp exceptionHandler +%endmacro + +%macro isr_error 1 + global isrHandler%1 + isrHandler%1: + push byte %1 + jmp exceptionHandler +%endmacro + +isrs: + isr 0 + isr 1 + isr 2 + isr 3 + isr 4 + isr 5 + isr 6 + isr 7 + isr_error 8 + isr 9 + isr_error 10 + isr_error 11 + isr_error 12 + isr_error 13 + isr_error 14 + isr 15 + isr 16 + isr_error 17 + isr 18 + isr 19 + isr 20 + isr 21 + isr 22 + isr 23 + isr 24 + isr 25 + isr 26 + isr 27 + isr 28 + isr 29 + isr_error 30 + isr 31 + +extern handleException + +exceptionHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleException + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/exceptions.c b/src/kernel/drivers/interrupts/exceptions.c new file mode 100644 index 0000000..8d82af9 --- /dev/null +++ b/src/kernel/drivers/interrupts/exceptions.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include <_stdio.h> + +char* EXCEPTION_MESSAGES[] = { + "DIVIDE BY ZERO", + "DEBUG", + "NON-MASKABLE INTERRUPT", + "BREAKPOINT", + "OVERFLOW", + "BOUND RAGE EXCEEDED", + "INVALID OPCODE", + "DEVICE NOT AVAILABLE", + "DOUBLE FAULT", + "COPROCESSOR SEGMENT OVERRUN", + "INVALID TSS", + "SEGMENT NOT PRESENT", + "STACK SEGMENT FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT", + "RESERVED", + "x87 FLOATING-POINT-EXCEPTION", + "ALIGNMENT CHECK", + "MACHINE CHECK", + "SMID FLOATING-POINT-EXCEPTION", + "VIRTUALIZATION EXCEPTION", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "RESERVED", + "SECURITY EXCEPTION", + "RESERVED" +}; + +void setupExceptions() { + printf("setting exceptions\n"); + setInterrupt(0, &isrHandler0); + setInterrupt(1, &isrHandler1); + setInterrupt(2, &isrHandler2); + setInterrupt(3, &isrHandler3); + setInterrupt(4, &isrHandler4); + setInterrupt(5, &isrHandler5); + setInterrupt(6, &isrHandler6); + setInterrupt(7, &isrHandler7); + setInterrupt(8, &isrHandler8); + setInterrupt(9, &isrHandler9); + setInterrupt(10, &isrHandler10); + setInterrupt(11, &isrHandler11); + setInterrupt(12, &isrHandler12); + setInterrupt(13, &isrHandler13); + setInterrupt(14, &isrHandler14); + setInterrupt(15, &isrHandler15); + setInterrupt(16, &isrHandler16); + setInterrupt(17, &isrHandler17); + setInterrupt(18, &isrHandler18); + setInterrupt(19, &isrHandler19); + setInterrupt(20, &isrHandler20); + setInterrupt(21, &isrHandler21); + setInterrupt(22, &isrHandler22); + setInterrupt(23, &isrHandler23); + setInterrupt(24, &isrHandler24); + setInterrupt(25, &isrHandler25); + setInterrupt(26, &isrHandler26); + setInterrupt(27, &isrHandler27); + setInterrupt(28, &isrHandler28); + setInterrupt(29, &isrHandler29); + setInterrupt(30, &isrHandler30); + setInterrupt(31, &isrHandler31); +} + +void handleException(regs* registers) { + printf("exception %s was raised with error code 0x%x!\n", EXCEPTION_MESSAGES[registers->int_no], registers->err_code); + yields(); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/interrupts.c b/src/kernel/drivers/interrupts/interrupts.c new file mode 100644 index 0000000..7c2f4b8 --- /dev/null +++ b/src/kernel/drivers/interrupts/interrupts.c @@ -0,0 +1,33 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include +#include +#include + +IDTR idtr; +IDTEntry* entries; +void* buffer; + +void setInterrupt(uint8_t vector, void* callback) { + IDTEntry* descriptor = &entries[vector]; + descriptor->isr_low = (uint32_t)callback & 0xFFFF; + descriptor->codeSegment = 0x08; + descriptor->attributes = 0x8E; + descriptor->isr_high = (uint32_t)callback >> 16; + descriptor->reserved = 0; +} + + +void initInterrupts() { + buffer = malloc(sizeof(IDTEntry) * 257); + entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3); + idtr.limit = sizeof(IDTEntry) * 256 - 1; + idtr.base = (uint32_t) entries; + setupExceptions(); + setupIRQs(); + __asm__ volatile ("lidt %0" : : "memory"(idtr)); + __asm__ volatile ("sti"); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.asm b/src/kernel/drivers/interrupts/irqs.asm new file mode 100644 index 0000000..3e6670b --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.asm @@ -0,0 +1,52 @@ +%macro irq 1 + global irqHandler%1 + irqHandler%1: + cli + push byte 0 + push byte %1+32 + jmp irqHandler +%endmacro + +irqs: + irq 0 + irq 1 + irq 2 + irq 3 + irq 4 + irq 5 + irq 6 + irq 7 + irq 8 + irq 9 + irq 10 + irq 11 + irq 12 + irq 13 + irq 14 + irq 15 + +extern handleIRQ + +irqHandler: + pusha + push ds + push es + push fs + push gs + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push eax + mov eax, handleIRQ + call eax + pop eax + pop gs + pop fs + pop es + pop ds + popa + add esp, 8 + iret \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/irqs.c b/src/kernel/drivers/interrupts/irqs.c new file mode 100644 index 0000000..c7bf183 --- /dev/null +++ b/src/kernel/drivers/interrupts/irqs.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include <_stdio.h> + +#define OFFSET_1 32 +#define OFFSET_2 40 + +void remapPIC(int offset1, int offset2) { + printf("remapping PIC\n"); + outb(0x20, 0x11); + outb(0xA0, 0x11); + outb(0x21, 0x20); + outb(0xA1, offset1); + outb(0x21, offset2); + outb(0xA1, 0x02); + outb(0x21, 0x01); + outb(0xA1, 0x01); + outb(0x21, 0x0); + outb(0xA1, 0x0); +} + +void setupIRQs() { + printf("setting IRQs\n"); + setInterrupt(OFFSET_1 + 0, &irqHandler0); + setInterrupt(OFFSET_1 + 1, &irqHandler1); + setInterrupt(OFFSET_1 + 2, &irqHandler2); + setInterrupt(OFFSET_1 + 3, &irqHandler3); + setInterrupt(OFFSET_1 + 4, &irqHandler4); + setInterrupt(OFFSET_1 + 5, &irqHandler5); + setInterrupt(OFFSET_1 + 6, &irqHandler6); + setInterrupt(OFFSET_1 + 7, &irqHandler7); + setInterrupt(OFFSET_2 + 0, &irqHandler8); + setInterrupt(OFFSET_2 + 1, &irqHandler9); + setInterrupt(OFFSET_2 + 2, &irqHandler10); + setInterrupt(OFFSET_2 + 3, &irqHandler11); + setInterrupt(OFFSET_2 + 4, &irqHandler12); + setInterrupt(OFFSET_2 + 5, &irqHandler13); + setInterrupt(OFFSET_2 + 6, &irqHandler14); + setInterrupt(OFFSET_2 + 7, &irqHandler15); + remapPIC(OFFSET_1, OFFSET_2); +} + +void* irqHandlers[16]; + +void setIRQHandler(uint8_t irqNumber, void* fun) { + irqHandlers[irqNumber] = fun; +} + +void handleIRQ(regs* registers) { + if (registers->int_no >= OFFSET_2) { + outb(0xA0, 0x20); + } + outb(0x20, 0x20); + uint8_t irqNumber = registers->int_no - OFFSET_1; + void (*handler)() = irqHandlers[irqNumber]; + if (handler) { + handler(); + return; + } + printf("unhandeled IRQ no. 0x%x was triggered!\n", irqNumber); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c new file mode 100644 index 0000000..dd4dcb9 --- /dev/null +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -0,0 +1,45 @@ +#include +#include +#include <_stdio.h> +#include +#include +#include + +uint64_t pressedKeys1 = 0; +uint64_t pressedKeys2 = 0; + +unsigned char keycodes[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '-', '=', '\b', + '\t', + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0,'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', 0, + '*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0 +}; + +void keyboardHandler() { + int i, scancode; + for(i = 1000; i > 0; i++) { + if ((inb(0x64) & 1) == 0) { + continue; + } + scancode = inb(0x60); + break; + } + if(i > 0) { + if(scancode & 0x80) { + } + else { + putChar(keycodes[scancode]); + yields(); + } + } +} + +void setupKeyboard() { + setIRQHandler(1, &keyboardHandler); +} \ No newline at end of file diff --git a/src/kernel/drivers/interrupts/timer/timer.c b/src/kernel/drivers/interrupts/timer/timer.c new file mode 100644 index 0000000..b9ba3af --- /dev/null +++ b/src/kernel/drivers/interrupts/timer/timer.c @@ -0,0 +1,51 @@ +#include +#include <_stdio.h> +#include +#include +#include +#include + + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +void setTimerFreq(uint32_t hz) { + int divisor = PIT_SCALE / hz; + outb(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0); + outb(PIT_A, (uint8_t) divisor); + outb(PIT_A, (uint8_t) (divisor >> 8)); +} + +uint32_t timerMillis = 0; + +void timerHandler() { + timerMillis++; + if (timerMillis % 1000 == 0) { + // printf("second\n"); + // yields(); + } +} + +void setupTimer() { + printf("setting timer frequency to 1kHz\n"); + setTimerFreq(1000); + setIRQHandler(0, &timerHandler); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index 5e71b2d..f998bd6 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -10,10 +10,14 @@ #include <_stdio.h> uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; -char format = 0x0F; +uint8_t format = 0x0A; -void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { - *(framebuffer + position) = c; +void setTextStyle(uint8_t style) { + format = style; +} + +void putCharWithFormatAtOffset(uint16_t c, uint16_t offset) { + *(framebuffer + offset) = c; } void putCharWithFormatAtPosition(uint8_t x, uint8_t y, uint32_t c) { @@ -21,7 +25,7 @@ } void putCharAtOffset(char c, uint16_t offset) { - putCharWithFormatAtOffset(c | format << 8, offset); + putCharWithFormatAtOffset((uint16_t) c | (uint16_t) format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { @@ -71,6 +75,9 @@ newLine(); return; } + if (c == 0x00) { + return; + } uint16_t offset = getCursorOffset(); putCharAtOffset(c, offset); setCursorOffset(offset + 1); @@ -86,6 +93,13 @@ char HEX_CHARS[] = "0123456789ABCDEF"; void putHex(char** write, uint32_t x) { + if (x == 0) { + **write = HEX_CHARS[x]; + (*write)++; + **write = HEX_CHARS[x]; + (*write)++; + return; + } bool alreadyWriting = false; for (int position = 3; position >= 0; position--) { uint8_t byte = (x >> (position * 8)) & 0xFF; @@ -93,7 +107,7 @@ alreadyWriting = true; } if (alreadyWriting) { - **write = HEX_CHARS[byte >> 8]; + **write = HEX_CHARS[byte >> 4]; (*write)++; **write = HEX_CHARS[byte & 0x0F]; (*write)++; @@ -189,10 +203,6 @@ } } -void setTextStyle(uint8_t style) { - format = style; -} - void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { if (string[i] == '\n') { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 75f4624..b442fac 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include extern uint32_t _kernel_end; @@ -15,9 +17,8 @@ initOSTasks(); drawLogo(); printf("initializing interrupts\n"); + setupDevices(); initInterrupts(); yields(); - setupTimer(); while(1); - yield(); } \ No newline at end of file diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index 5d52a79..adf2dba 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -9,7 +9,6 @@ void printLoop() { clearScreen(); - setTextStyle(0x0F); while (1) { Message* message = popMessage(&printerTask); if (message == 0) { diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 4b93d2d..3964e7c 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -2,7 +2,7 @@ #include #include <_stdio.h> -#define STACK_SIZE 0x1000 +#define STACK_SIZE 0x100000 Task *currentTask; @@ -26,8 +26,8 @@ Task* last = currentTask; currentTask = last->nextTask; if (currentTask == 0x00) { - puts("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1); + return; } last->nextTask = 0x00; switchTask(&(last->registers), &(currentTask->registers)); @@ -35,6 +35,11 @@ void schedule(Task* task) { Task* test = currentTask; + if (currentTask == 0x00) { + currentTask = task; + currentTask->nextTask = 0x00; + return; + } while (test->nextTask != 0x0) { if (test->nextTask == task) { return; // don't schedule if the task is already in the queue diff --git a/src/kernel/util/tree-os.c b/src/kernel/util/tree-os.c index 681c1e0..bb4c71c 100644 --- a/src/kernel/util/tree-os.c +++ b/src/kernel/util/tree-os.c @@ -1,5 +1,6 @@ #include #include <_stdio.h> +#include const char* logo = "\ _______ \n\ @@ -12,4 +13,6 @@ void drawLogo() { printf(logo); printf("TREE-OS v. alpha 0.1 (IN DEVELOPMENT)\n\n"); + yields(); + setTextStyle(0x0F); } \ No newline at end of file diff --git a/src/multiboot/boot.asm b/src/multiboot/boot.asm index 8498cb3..22eff15 100644 --- a/src/multiboot/boot.asm +++ b/src/multiboot/boot.asm @@ -13,7 +13,7 @@ extern kernelMain -KERNEL_STACK_SIZE equ 4096 ; 4kb of stack +KERNEL_STACK_SIZE equ 4096 * 32 ; 4kb of stack global _start section .text _start: