Compare commits
12 Commits
ca72196bf4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc6c0fd056 | ||
|
|
631ea7b7cb | ||
|
|
44330e8427 | ||
|
|
390fc87c20 | ||
|
|
fdff77afd1 | ||
|
|
a492161f0a | ||
|
|
fe0a4a6d3b | ||
|
|
6be1414484 | ||
|
|
bda171256f | ||
|
|
f778f38d9c | ||
|
|
0c1144eb8e | ||
|
|
623c3b5505 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ Makefile
|
||||
cmake_install.cmake
|
||||
.vscode/
|
||||
.vs/
|
||||
bx_enh_dbg.ini
|
||||
|
||||
@@ -7,7 +7,7 @@ set(CMAKE_ASM_COMPILER "i686-elf-as")
|
||||
set(CMAKE_C_COMPILER "i686-elf-gcc")
|
||||
set(CMAKE_CXX_COMPILER "i686-elf-g++")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-ffreestanding -O2 -fno-rtti -Wno-write-strings -Wno-multichar -Wno-unused-parameter -Wno-overflow -Wno-narrowing -fno-exceptions -Wno-trigraphs ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-ffreestanding -funroll-loops -O2 -fno-rtti -Wno-write-strings -Wno-multichar -Wno-unused-parameter -Wno-overflow -Wno-narrowing -fno-exceptions -Wno-trigraphs ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-T ../linker.ld -ffreestanding -O2 -nostdlib -lgcc -Wwrite-strings ${CMAKE_EXE_LINKER_FLAGS}")
|
||||
|
||||
include_directories(OwOS "./")
|
||||
@@ -22,12 +22,14 @@ file(GLOB DRIV_DISP_VGA "kernel/drivers/terminal/*.cpp" "kernel/drivers/termina
|
||||
|
||||
# Lib source
|
||||
file(GLOB LIB_STD "lib/std/*.cpp" "lib/std/*.asm")
|
||||
file(GLOB LIB_KERN_LOG "lib/kernel/logger/*.cpp" "lib/kernel/logger/*.asm")
|
||||
|
||||
|
||||
|
||||
add_executable(OwOS ${KERN_SRC} ${KERN_LIB_SRC}
|
||||
${DRIV_DISP_VGA}
|
||||
${LIB_STD})
|
||||
${LIB_STD} ${LIB_KERN_LOG})
|
||||
|
||||
|
||||
set_target_properties(OwOS PROPERTIES OUTPUT_NAME "OwOS.bin")
|
||||
|
||||
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Benjamin Kyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,2 +1,7 @@
|
||||
# OwOS
|
||||
|
||||
An x86 microkernel written in C++ (and some assembly) with a twist. It's awful, not just at being an OS but it's called OwOS.
|
||||
|
||||
But yea its a hobbyist microkernel (and maybe shell) written in C++
|
||||
|
||||
Its actually not a microkernel at all (yet)
|
||||
|
||||
BIN
build/OwOS.bin
BIN
build/OwOS.bin
Binary file not shown.
BIN
build/OwOS.iso
BIN
build/OwOS.iso
Binary file not shown.
Binary file not shown.
@@ -37,9 +37,10 @@ _start:
|
||||
jmp 1b
|
||||
|
||||
|
||||
.global ASM_INIT_FPU
|
||||
.global FPU_Init
|
||||
.type FPU_Init, @function
|
||||
|
||||
ASM_INIT_FPU:
|
||||
FPU_Init:
|
||||
# FPU Config
|
||||
VAL_037F:
|
||||
.hword 0x037F
|
||||
@@ -57,5 +58,6 @@ ASM_INIT_FPU:
|
||||
fldcw VAL_037E
|
||||
fldcw VAL_037A
|
||||
fninit
|
||||
ret
|
||||
|
||||
.size _start, . - _start
|
||||
|
||||
68
kernel.cpp
68
kernel.cpp
@@ -1,28 +1,62 @@
|
||||
#include <lib/std/stdlib.h>
|
||||
#include <kernel/multiboot.h>
|
||||
#include <kernel/kernio.h>
|
||||
|
||||
#include <kernel/drivers/terminal/terminal.h>
|
||||
|
||||
#include <kernel/kernio.h>
|
||||
#include <kernel/panic.h>
|
||||
#include <kernel/pic.h>
|
||||
#include <kernel/gdt.h>
|
||||
#include <kernel/idt.h>
|
||||
|
||||
#include <lib/std/stdlib.h>
|
||||
#include <lib/std/memory.h>
|
||||
#include <lib/kernel/logger/logger.h>
|
||||
|
||||
extern "C" {
|
||||
extern void FPU_Init(void);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
int kernel_main(uint32_t magic, multibootInfo_t* multiboot) {
|
||||
cls();
|
||||
showCursor();
|
||||
setFGColour(VGA_GREEN);
|
||||
write("OwOS V0.2 ");
|
||||
writeln("Starting Up...");
|
||||
setFGColour(VGA_WHITE);
|
||||
nline();
|
||||
|
||||
int kernel_main(uint32_t magic, MultibootInfo_t* multiboot) {
|
||||
Cls();
|
||||
ShowCursor();
|
||||
SetFGColour(VGA_GREEN);
|
||||
Writeln("OwOS V0.2 Starting Up...");
|
||||
SetFGColour(VGA_WHITE);
|
||||
Nline();
|
||||
|
||||
write("OwO, What's This? ");
|
||||
write("*notices ");
|
||||
write(itoa(multiboot->mem_upper / 1024));
|
||||
write("mb of ram*");
|
||||
setFGColour(VGA_BRIGHT_MAGENTA);
|
||||
nline(); nline(); nline();
|
||||
// Init systems
|
||||
|
||||
FPU_Init();
|
||||
loggerOK("FPU Init");
|
||||
|
||||
write("~#");
|
||||
GDT_Init();
|
||||
loggerOK("GDT Init");
|
||||
|
||||
PIC_Default_Remap();
|
||||
loggerOK("PIC Remapped");
|
||||
|
||||
IDT_Init();
|
||||
loggerOK("IDT Init");
|
||||
|
||||
Nline(); Nline();
|
||||
Write("OwO, What's This?");
|
||||
SetFGColour(VGA_BRIGHT_MAGENTA);
|
||||
Write(" *notices ");
|
||||
Write(itoa(multiboot->mem_upper / 1024));
|
||||
Writeln("mb of ram*");
|
||||
SetFGColour(VGA_WHITE);
|
||||
Nline();
|
||||
|
||||
SetFGColour(VGA_YELLOW);
|
||||
Writeln("Welcome to OwOS");
|
||||
SetFGColour(VGA_BRIGHT_MAGENTA);
|
||||
Write("~#");
|
||||
|
||||
asm("sti");
|
||||
|
||||
// PanicKernel(0x00, "Self Triggered Panic", "kernel.cpp:48", "kernel_main(uint32_t magic, MultibootInfo_t* multiboot)");
|
||||
|
||||
for (;;)
|
||||
asm("hlt");
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
#include <kernel/kernio.h>
|
||||
#include <lib/std/string.h>
|
||||
|
||||
static const int TERMINAL_WIDTH = 80;
|
||||
static const int TERMINAL_HEIGHT = 24;
|
||||
|
||||
static VGAChar_t* frameBuffer = (VGAChar_t*)0xB8000;
|
||||
|
||||
static char clearColour = 0x0;
|
||||
@@ -14,74 +11,79 @@ static char fgColour = 0xF;
|
||||
|
||||
Cursor cursor;
|
||||
|
||||
void cls() {
|
||||
void Cls() {
|
||||
for (uint8_t x = 0; x < TERMINAL_WIDTH; x++)
|
||||
for (uint8_t y = 0; y < TERMINAL_HEIGHT; y++)
|
||||
puts(x, y, ' ', fgColour, clearColour);
|
||||
Puts(x, y, ' ', fgColour, clearColour);
|
||||
|
||||
cursor.x = 0; cursor.y = 0;
|
||||
updateCursor(cursor);
|
||||
UpdateCursor(cursor);
|
||||
}
|
||||
|
||||
void puts(char input) {
|
||||
void Puts(char input) {
|
||||
if (cursor.x + 1 > TERMINAL_WIDTH) {
|
||||
nline();
|
||||
Nline();
|
||||
}
|
||||
if (input == '\n') {
|
||||
nline();
|
||||
Nline();
|
||||
} else {
|
||||
puts(cursor.x, cursor.y, input, fgColour, bgColour);
|
||||
Puts(cursor.x, cursor.y, input, fgColour, bgColour);
|
||||
cursor.x++;
|
||||
}
|
||||
updateCursor(cursor);
|
||||
UpdateCursor(cursor);
|
||||
}
|
||||
|
||||
void puts(int x, int y, char c, char foreground, char background) {
|
||||
void Puts(int x, int y, char c, char foreground, char background) {
|
||||
frameBuffer[(y * TERMINAL_WIDTH) + x].c = c;
|
||||
frameBuffer[(y * TERMINAL_WIDTH) + x].foreground = foreground;
|
||||
frameBuffer[(y * TERMINAL_WIDTH) + x].background = background;
|
||||
}
|
||||
|
||||
void nline() {
|
||||
void Nline() {
|
||||
cursor.y++;
|
||||
cursor.x = 0;
|
||||
updateCursor(cursor);
|
||||
UpdateCursor(cursor);
|
||||
}
|
||||
|
||||
void write(char* input) {
|
||||
void Write(char* input) {
|
||||
for (uint32_t i = 0; i < strlen(input); i++) {
|
||||
if (cursor.x + 1 > TERMINAL_WIDTH) {
|
||||
nline();
|
||||
Nline();
|
||||
}
|
||||
if (input[i] == '\n') {
|
||||
nline();
|
||||
Nline();
|
||||
}
|
||||
else {
|
||||
puts(cursor.x, cursor.y, input[i], fgColour, bgColour);
|
||||
Puts(cursor.x, cursor.y, input[i], fgColour, bgColour);
|
||||
cursor.x++;
|
||||
}
|
||||
}
|
||||
updateCursor(cursor);
|
||||
UpdateCursor(cursor);
|
||||
}
|
||||
|
||||
void writeln(char* input) {
|
||||
write(input);
|
||||
nline();
|
||||
void Writeln(char* input) {
|
||||
Write(input);
|
||||
Nline();
|
||||
}
|
||||
|
||||
void setClearColour(char col) {
|
||||
void SetClearColour(char col) {
|
||||
clearColour = col;
|
||||
}
|
||||
|
||||
void setFGColour(char col) {
|
||||
void SetFGColour(char col) {
|
||||
fgColour = col;
|
||||
}
|
||||
|
||||
void setBGColour(char col) {
|
||||
void SetBGColour(char col) {
|
||||
bgColour = col;
|
||||
}
|
||||
|
||||
void showCursor() {
|
||||
void ResetTermColours() {
|
||||
bgColour = 0x0;
|
||||
fgColour = 0xF;
|
||||
}
|
||||
|
||||
void ShowCursor() {
|
||||
outb(0x3D4, 0x0A);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xC0) | 0x0); // Cursor start top
|
||||
|
||||
@@ -89,12 +91,12 @@ void showCursor() {
|
||||
outb(0x3D5, (inb(0x3D5) & 0xE0) | 0xF); // Cursor start bottom
|
||||
}
|
||||
|
||||
void hideCursor() {
|
||||
void HideCursor() {
|
||||
outb(0x3D4, 0x0A);
|
||||
outb(0x3D5, 0x20);
|
||||
}
|
||||
|
||||
void updateCursor(Cursor c) {
|
||||
void UpdateCursor(Cursor c) {
|
||||
uint16_t pos = c.y * TERMINAL_WIDTH + c.x;
|
||||
|
||||
outb(0x3D4, 0x0F);
|
||||
@@ -103,9 +105,13 @@ void updateCursor(Cursor c) {
|
||||
outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void setCursorPosition(int x, int y) {
|
||||
void SetCursorPosition(int x, int y) {
|
||||
cursor.x = x; cursor.y = y;
|
||||
updateCursor(cursor);
|
||||
UpdateCursor(cursor);
|
||||
}
|
||||
|
||||
Cursor GetCursorPosition() {
|
||||
return cursor;
|
||||
}
|
||||
|
||||
uint8_t getVGACol(char f, char b) {
|
||||
|
||||
@@ -32,22 +32,27 @@ struct Cursor {
|
||||
uint8_t y;
|
||||
} __attribute__((packed));
|
||||
|
||||
void cls();
|
||||
static const int TERMINAL_WIDTH = 80;
|
||||
static const int TERMINAL_HEIGHT = 24;
|
||||
|
||||
void puts(char input);
|
||||
void puts(int x, int y, char c, char foreground, char background);
|
||||
void Cls();
|
||||
|
||||
void nline();
|
||||
void Puts(char input);
|
||||
void Puts(int x, int y, char c, char foreground, char background);
|
||||
|
||||
void write(char* input);
|
||||
void writeln(char* input);
|
||||
void Nline();
|
||||
|
||||
void setClearColour(char col);
|
||||
void setFGColour(char col);
|
||||
void setBGColour(char col);
|
||||
void Write(char* input);
|
||||
void Writeln(char* input);
|
||||
|
||||
void showCursor();
|
||||
void hideCursor();
|
||||
void SetClearColour(char col);
|
||||
void SetFGColour(char col);
|
||||
void SetBGColour(char col);
|
||||
void ResetTermColours();
|
||||
|
||||
void updateCursor(Cursor c);
|
||||
void setCursorPosition(int x, int y);
|
||||
void ShowCursor();
|
||||
void HideCursor();
|
||||
|
||||
void UpdateCursor(Cursor c);
|
||||
void SetCursorPosition(int x, int y);
|
||||
Cursor GetCursorPosition();
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "gdt.h"
|
||||
|
||||
#include <kernel/kernio.h>
|
||||
#include <lib/std/memory.h>
|
||||
|
||||
struct SegmentDescriptor_t {
|
||||
uint16_t limit_low;
|
||||
uint16_t base_low;
|
||||
uint8_t base_middle;
|
||||
uint8_t access;
|
||||
uint8_t granularity0:4;
|
||||
uint8_t granularity1:4;
|
||||
uint8_t base_high;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GDT_t {
|
||||
uint16_t limit;
|
||||
uint32_t base;
|
||||
} __attribute__((packed));
|
||||
|
||||
SegmentDescriptor_t _GDT[5];
|
||||
GDT_t _GDTptr;
|
||||
|
||||
void lgdt(GDT_t GDT) {
|
||||
asm ("lgdt %0" : : "m"(GDT));
|
||||
}
|
||||
|
||||
void GDT_Init() {
|
||||
_GDTptr.limit = (sizeof(SegmentDescriptor_t) * 5) - 1;
|
||||
_GDTptr.base = (uint32_t)&_GDT;
|
||||
|
||||
// Null segment
|
||||
GDT_Set_Gate(0, 0, 0, 0, 0);
|
||||
// Code Base 0 limit 32 Access EXEC + RW
|
||||
GDT_Set_Gate(1, 0x00000000, 0xFFFFFFFF, GDT_ACCESS_PRESENT | GDT_ACCESS_EXEC | GDT_ACCESS_RW, GDT_FLAG_GR_PAGE | GDT_FLAG_SZ_32B);
|
||||
// Data Base 0 Limit 32 Access RW
|
||||
GDT_Set_Gate(2, 0x00000000, 0xFFFFFFFF, GDT_ACCESS_PRESENT | GDT_ACCESS_RW, GDT_FLAG_GR_PAGE | GDT_FLAG_SZ_32B);
|
||||
|
||||
lgdt(_GDTptr);
|
||||
SEGMENTS_RELOAD();
|
||||
}
|
||||
|
||||
void GDT_Set_Gate(uint32_t index, uint32_t baseAddr, uint32_t limitAddr, uint8_t accessLvl, uint8_t flags) {
|
||||
if (index > 5) return;
|
||||
_GDT[index].base_low = (baseAddr & 0xFFFF);
|
||||
_GDT[index].base_middle = (baseAddr >> 16) & 0xFF;
|
||||
_GDT[index].base_high = (baseAddr >> 24) & 0xFF;
|
||||
|
||||
_GDT[index].limit_low = (limitAddr >> 0) & 0xFFFF;
|
||||
_GDT[index].granularity0 = (limitAddr >> 16) & 0x0F;
|
||||
|
||||
_GDT[index].granularity1 = flags & 0x0F;
|
||||
_GDT[index].access = accessLvl;
|
||||
}
|
||||
|
||||
|
||||
23
kernel/gdt.h
23
kernel/gdt.h
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <lib/stdint.h>
|
||||
|
||||
#define GDT_ACCESS_PRESENT 0x90
|
||||
#define GDT_ACCESS_PR_TSS 0x80
|
||||
#define GDT_ACCESS_PRIV_3 0x60
|
||||
#define GDT_ACCESS_PRIV_2 0x40
|
||||
#define GDT_ACCESS_PRIV_1 0x20
|
||||
#define GDT_ACCESS_EXEC 0x08
|
||||
#define GDT_ACCESS_DIR_D 0x04
|
||||
#define GDT_ACCESS_RW 0x02
|
||||
#define GDT_ACCESS_ACCESSED 0x01
|
||||
|
||||
#define GDT_FLAG_GR_PAGE 0x08
|
||||
#define GDT_FLAG_SZ_32B 0x04
|
||||
|
||||
extern "C" {
|
||||
extern void SEGMENTS_RELOAD(void);
|
||||
}
|
||||
|
||||
void GDT_Init();
|
||||
void GDT_Set_Gate(uint32_t index, uint32_t baseAddr, uint32_t limitAddr, uint8_t accessLvl, uint8_t flags);
|
||||
|
||||
81
kernel/idt.cpp
Normal file
81
kernel/idt.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "idt.h"
|
||||
|
||||
#include <kernel/drivers/terminal/terminal.h>
|
||||
#include <lib/std/stdlib.h>
|
||||
|
||||
struct IDT_Descriptor_t {
|
||||
uint16_t offset_low;
|
||||
uint16_t selector;
|
||||
uint8_t zero;
|
||||
uint8_t type_attr;
|
||||
uint16_t offset_high;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct IDT_t {
|
||||
uint16_t limit;
|
||||
uint32_t base;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
IDT_Descriptor_t _IDT[256];
|
||||
IDT_t _IDTptr;
|
||||
|
||||
void lidt(IDT_t IDT) {
|
||||
asm("lidt %0" : : "m"(IDT));
|
||||
}
|
||||
|
||||
void IDT_Set_Gate(uint8_t i, uint32_t offset, uint16_t selector, uint8_t attrib);
|
||||
|
||||
void IDT_Init() {
|
||||
_IDTptr.limit = (sizeof(IDT_Descriptor_t) * 256) - 1;
|
||||
_IDTptr.base = (uint32_t)&_IDT;
|
||||
|
||||
for (uint16_t i = 0; i < 256; i++)
|
||||
IDT_Set_Gate(i, (uint32_t)&ISR_DEFAULT, 0x01, IDT_ATTR_PRESENT | IDT_TRAP_GATE | IDT_ATTR_PRIV_3);
|
||||
|
||||
IDT_Set_Gate(0x00, (uint32_t)&ISR0, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x01, (uint32_t)&ISR1, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x02, (uint32_t)&ISR2, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x03, (uint32_t)&ISR3, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x04, (uint32_t)&ISR4, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x05, (uint32_t)&ISR5, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x06, (uint32_t)&ISR6, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x07, (uint32_t)&ISR7, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x08, (uint32_t)&ISR8, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x09, (uint32_t)&ISR9, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x0A, (uint32_t)&ISR10, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x0B, (uint32_t)&ISR11, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x0C, (uint32_t)&ISR12, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x0D, (uint32_t)&ISR13, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x0E, (uint32_t)&ISR14, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x0F, (uint32_t)&ISR15, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x10, (uint32_t)&ISR16, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x11, (uint32_t)&ISR17, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x12, (uint32_t)&ISR18, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x13, (uint32_t)&ISR19, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x14, (uint32_t)&ISR20, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x15, (uint32_t)&ISR21, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x16, (uint32_t)&ISR22, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x17, (uint32_t)&ISR23, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x18, (uint32_t)&ISR24, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x19, (uint32_t)&ISR25, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x1A, (uint32_t)&ISR26, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x1B, (uint32_t)&ISR27, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x1C, (uint32_t)&ISR28, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x1D, (uint32_t)&ISR29, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x1E, (uint32_t)&ISR30, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
IDT_Set_Gate(0x1F, (uint32_t)&ISR31, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
|
||||
IDT_Set_Gate(0x21, (uint32_t)&ISR_KBD, 0x01, IDT_ATTR_PRESENT | IDT_INT_GATE);
|
||||
|
||||
lidt(_IDTptr);
|
||||
}
|
||||
|
||||
void IDT_Set_Gate(uint8_t i, uint32_t offset, uint16_t selector, uint8_t attrib) {
|
||||
if (i > 256) return;
|
||||
_IDT[i].offset_low = offset & 0xFFFF;
|
||||
_IDT[i].selector = selector * 8;
|
||||
_IDT[i].zero = 0;
|
||||
_IDT[i].type_attr = attrib;
|
||||
_IDT[i].offset_high = (offset & 0xFFFF) >> 16;
|
||||
}
|
||||
55
kernel/idt.h
Normal file
55
kernel/idt.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <lib/stdint.h>
|
||||
|
||||
#define IDT_ATTR_PRESENT 0x80
|
||||
#define IDT_ATTR_PRIV_3 0x60
|
||||
#define IDT_ATTR_PRIV_2 0x40
|
||||
#define IDT_ATTR_PRIV_1 0x20
|
||||
#define IDT_INT_GATE 0x0E
|
||||
#define IDT_TRAP_GATE 0x0F
|
||||
#define IDT_TASK_GATE 0x15
|
||||
|
||||
|
||||
void IDT_Init();
|
||||
void IDT_Set_Gate();
|
||||
|
||||
#define ISR_DEF(id) extern void ISRid(void)
|
||||
|
||||
extern "C" {
|
||||
extern void ISR_DEFAULT(void);
|
||||
extern void ISR_KBD(void);
|
||||
|
||||
extern void ISR0(void);
|
||||
extern void ISR1(void);
|
||||
extern void ISR2(void);
|
||||
extern void ISR3(void);
|
||||
extern void ISR4(void);
|
||||
extern void ISR5(void);
|
||||
extern void ISR6(void);
|
||||
extern void ISR7(void);
|
||||
extern void ISR8(void);
|
||||
extern void ISR9(void);
|
||||
extern void ISR10(void);
|
||||
extern void ISR11(void);
|
||||
extern void ISR12(void);
|
||||
extern void ISR13(void);
|
||||
extern void ISR14(void);
|
||||
extern void ISR15(void);
|
||||
extern void ISR16(void);
|
||||
extern void ISR17(void);
|
||||
extern void ISR18(void);
|
||||
extern void ISR19(void);
|
||||
extern void ISR20(void);
|
||||
extern void ISR21(void);
|
||||
extern void ISR22(void);
|
||||
extern void ISR23(void);
|
||||
extern void ISR24(void);
|
||||
extern void ISR25(void);
|
||||
extern void ISR26(void);
|
||||
extern void ISR27(void);
|
||||
extern void ISR28(void);
|
||||
extern void ISR29(void);
|
||||
extern void ISR30(void);
|
||||
extern void ISR31(void);
|
||||
}
|
||||
272
kernel/isr.asm
Normal file
272
kernel/isr.asm
Normal file
@@ -0,0 +1,272 @@
|
||||
.align 4
|
||||
.global ISR0
|
||||
.global ISR1
|
||||
.global ISR2
|
||||
.global ISR3
|
||||
.global ISR4
|
||||
.global ISR5
|
||||
.global ISR6
|
||||
.global ISR7
|
||||
.global ISR8
|
||||
.global ISR9
|
||||
.global ISR10
|
||||
.global ISR11
|
||||
.global ISR12
|
||||
.global ISR13
|
||||
.global ISR14
|
||||
.global ISR15
|
||||
.global ISR16
|
||||
.global ISR17
|
||||
.global ISR18
|
||||
.global ISR19
|
||||
.global ISR20
|
||||
.global ISR21
|
||||
.global ISR22
|
||||
.global ISR23
|
||||
.global ISR24
|
||||
.global ISR25
|
||||
.global ISR26
|
||||
.global ISR27
|
||||
.global ISR28
|
||||
.global ISR29
|
||||
.global ISR30
|
||||
.global ISR31
|
||||
|
||||
ISR0:
|
||||
cli
|
||||
push $0
|
||||
push $0
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR1:
|
||||
cli
|
||||
push $0
|
||||
push $1
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR2:
|
||||
cli
|
||||
push $0
|
||||
push $2
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR3:
|
||||
cli
|
||||
push $0
|
||||
push $3
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR4:
|
||||
cli
|
||||
push $0
|
||||
push $4
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR5:
|
||||
cli
|
||||
push $0
|
||||
push $5
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR6:
|
||||
cli
|
||||
push $0
|
||||
push $6
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR7:
|
||||
cli
|
||||
push $0
|
||||
push $7
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR8:
|
||||
cli
|
||||
push $8
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR9:
|
||||
cli
|
||||
push $9
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR10:
|
||||
cli
|
||||
push $10
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR11:
|
||||
cli
|
||||
push $11
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR12:
|
||||
cli
|
||||
push $12
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR13:
|
||||
cli
|
||||
push $13
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR14:
|
||||
cli
|
||||
push $14
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR15:
|
||||
cli
|
||||
push $15
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR16:
|
||||
cli
|
||||
push $16
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR17:
|
||||
cli
|
||||
push $17
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR18:
|
||||
cli
|
||||
push $18
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR19:
|
||||
cli
|
||||
push $19
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR20:
|
||||
cli
|
||||
push $20
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR21:
|
||||
cli
|
||||
push $21
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR22:
|
||||
cli
|
||||
push $22
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR23:
|
||||
cli
|
||||
push $23
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR24:
|
||||
cli
|
||||
push $24
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR25:
|
||||
cli
|
||||
push $25
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR26:
|
||||
cli
|
||||
push $26
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR27:
|
||||
cli
|
||||
push $27
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR28:
|
||||
cli
|
||||
push 28
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR29:
|
||||
cli
|
||||
push $29
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR30:
|
||||
cli
|
||||
push $30
|
||||
jmp ISR_FAULT
|
||||
|
||||
ISR31:
|
||||
cli
|
||||
push $31
|
||||
jmp ISR_FAULT
|
||||
|
||||
.extern FaultHandler
|
||||
ISR_FAULT:
|
||||
pusha
|
||||
push %ds
|
||||
push %es
|
||||
push %fs
|
||||
push %gs
|
||||
movw $0x10,%ax
|
||||
movw %ax,%ds
|
||||
movw %ax,%es
|
||||
movw %ax,%fs
|
||||
movw %ax,%gs
|
||||
movl %esp,%eax
|
||||
pushl %eax
|
||||
call FaultHandler
|
||||
popl %eax
|
||||
popl %gs
|
||||
popl %fs
|
||||
popl %es
|
||||
popl %ds
|
||||
popa
|
||||
addl $8,%esp
|
||||
iret
|
||||
|
||||
.global ISR_DEFAULT
|
||||
.extern DEFAULT_ISR
|
||||
ISR_DEFAULT:
|
||||
pushal
|
||||
pushw %ds
|
||||
pushw %es
|
||||
pushw %fs
|
||||
pushw %gs
|
||||
pushl %ebx
|
||||
movw $0x10,%bx
|
||||
movw %bx,%ds
|
||||
popl %ebx
|
||||
|
||||
cld /* C code following the sysV ABI requires DF to be clear on function entry */
|
||||
call DEFAULT_ISR
|
||||
|
||||
popw %gs
|
||||
popw %fs
|
||||
popw %es
|
||||
popw %ds
|
||||
popal
|
||||
iret
|
||||
|
||||
.global ISR_KBD
|
||||
.extern KeyboardHandler
|
||||
ISR_KBD:
|
||||
pushal
|
||||
pushw %ds
|
||||
pushw %es
|
||||
pushw %fs
|
||||
pushw %gs
|
||||
pushl %ebx
|
||||
movw $0x10,%bx
|
||||
movw %bx,%ds
|
||||
popl %ebx
|
||||
|
||||
cld /* C code following the sysV ABI requires DF to be clear on function entry */
|
||||
call KeyboardHandler
|
||||
|
||||
popw %gs
|
||||
popw %fs
|
||||
popw %es
|
||||
popw %ds
|
||||
popal
|
||||
iret
|
||||
|
||||
68
kernel/isr.cpp
Normal file
68
kernel/isr.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
#include <kernel/drivers/terminal/terminal.h>
|
||||
#include <kernel/panic.h>
|
||||
#include <kernel/kernio.h>
|
||||
|
||||
struct Regs_t {
|
||||
unsigned int gs, fs, es, ds; /* pushed the segs last */
|
||||
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */
|
||||
unsigned int int_no, err_code; /* our 'push byte #' and ecodes do this */
|
||||
unsigned int eip, cs, eflags, useresp, ss; /* pushed by the processor automatically */
|
||||
};
|
||||
|
||||
char *PanicMessage[] = {
|
||||
"Division By Zero",
|
||||
"Debug",
|
||||
"Non Maskable Interrupt",
|
||||
"Break Point",
|
||||
"Into Detect Overflow",
|
||||
"Out of bounds Exception",
|
||||
"Invalid Opcode",
|
||||
"No Coprocessor",
|
||||
"Double Fault",
|
||||
"Coprocessor Segment Overrun",
|
||||
"Bad TSS Exception",
|
||||
"Segment not present",
|
||||
"Stack Fault",
|
||||
"General Protection Fault",
|
||||
"Page Fault",
|
||||
"Unknown Interrupt",
|
||||
"Coprocessor Fault",
|
||||
"Alignement Check Exception",
|
||||
"Machine Check Exception",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved",
|
||||
"Reserved"
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void DEFAULT_ISR() {
|
||||
outb(0x20,0x20);
|
||||
}
|
||||
|
||||
void KeyboardHandler() {
|
||||
Write("Keyboard Pressed! \n");
|
||||
outb(0x20,0x20);
|
||||
}
|
||||
|
||||
void FaultHandler(struct Regs_t* r) {
|
||||
if (r->int_no < 32) {
|
||||
uint32_t val;
|
||||
asm volatile ( "mov %%cr2, %0" : "=r"(val) );
|
||||
PanicKernel(val, PanicMessage[r->int_no], "kernel/isr.cpp:64", "FaultHandler(struct Regs_t* r)");
|
||||
for(;;) {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
#include "kernio.h"
|
||||
@@ -14,3 +14,32 @@ inline uint8_t inb(uint16_t port) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint16_t inw(uint16_t port) {
|
||||
uint16_t ret;
|
||||
asm ( "inw %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(port) );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void outw(uint16_t port, uint16_t val) {
|
||||
asm ( "outw %0, %1" : : "a"(val), "Nd"(port) );
|
||||
}
|
||||
|
||||
static inline uint32_t inl(uint16_t port) {
|
||||
uint32_t ret;
|
||||
asm ( "inl %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(port) );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void outl(uint16_t port, uint32_t val) {
|
||||
asm ( "outl %0, %1" : : "a"(val), "Nd"(port) );
|
||||
}
|
||||
|
||||
static inline void io_wait() {
|
||||
asm ( "jmp 1f\n\t"
|
||||
"1:jmp 2f\n\t"
|
||||
"2:" );
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <lib/stdint.h>
|
||||
|
||||
// Totally stolen from here https://forum.osdev.org/viewtopic.php?f=1&t=8881
|
||||
struct multibootInfo_t {
|
||||
struct MultibootInfo_t {
|
||||
uint32_t flags;
|
||||
uint32_t mem_lower;
|
||||
uint32_t mem_upper;
|
||||
|
||||
87
kernel/panic.cpp
Normal file
87
kernel/panic.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "panic.h"
|
||||
|
||||
#include <lib/stdint.h>
|
||||
#include <lib/std/stdlib.h>
|
||||
#include <lib/std/string.h>
|
||||
|
||||
#include <kernel/drivers/terminal/terminal.h>
|
||||
|
||||
void PanicKernel(char code, char* why, char* where, char* what) {
|
||||
asm("cli");
|
||||
|
||||
if (why == "") {
|
||||
switch (code) {
|
||||
case 0x00:
|
||||
why = "Self triggered panic";
|
||||
break;
|
||||
|
||||
default:
|
||||
why = "Uknown Error";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ResetTermColours();
|
||||
HideCursor();
|
||||
Cls();
|
||||
|
||||
SetBGColour(VGA_RED);
|
||||
for (uint8_t i = 0; i < TERMINAL_WIDTH; i++)
|
||||
Puts(' ');
|
||||
|
||||
SetCursorPosition(34, 0);
|
||||
Write("KERNEL PANIC");
|
||||
|
||||
ResetTermColours();
|
||||
SetFGColour(VGA_DARK_GREY);
|
||||
SetCursorPosition(1, 3);
|
||||
Write("OOPSIE WOOPSIE! WE MADE A FUCKIE WUCKIE!! A WIDDLE FUCKO BOINGO! \n THE CODE MONKEYS AT HEADQUARTERS ARE WORKING VEWWY HAWD TO FIX THIS!");
|
||||
|
||||
ResetTermColours();
|
||||
SetCursorPosition(1, 6);
|
||||
Write("EXCEPTION: ");
|
||||
Write(why);
|
||||
Puts(' ');
|
||||
Write(" (Error code 0x");
|
||||
Write(itohx(code));
|
||||
Puts(')');
|
||||
Nline(); Nline();
|
||||
|
||||
SetFGColour(VGA_GREY);
|
||||
Write(" at: ");
|
||||
Write(where);
|
||||
Puts(' ');
|
||||
|
||||
bool seenBracket = false;
|
||||
for(uint32_t i = 0; i < strlen(what); i++) {
|
||||
if (what[i] == '(')
|
||||
seenBracket = true;
|
||||
|
||||
if (GetCursorPosition().x > 60) {
|
||||
Write(" ...");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!seenBracket) {
|
||||
SetFGColour(VGA_YELLOW);
|
||||
} else {
|
||||
SetFGColour(VGA_GREY);
|
||||
}
|
||||
Puts(what[i]);
|
||||
}
|
||||
|
||||
|
||||
SetCursorPosition(0, TERMINAL_HEIGHT);
|
||||
SetBGColour(VGA_GREY);
|
||||
for (uint8_t i = 0; i < TERMINAL_WIDTH; i++)
|
||||
Puts(' ');
|
||||
|
||||
SetFGColour(VGA_BLACK);
|
||||
SetCursorPosition(1, TERMINAL_HEIGHT);
|
||||
Write("Error Code: 0x");
|
||||
Write(itohx(code));
|
||||
|
||||
for (;;) {
|
||||
asm("hlt");
|
||||
}
|
||||
}
|
||||
3
kernel/panic.h
Normal file
3
kernel/panic.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void PanicKernel(char code, char* why = "", char* where = "", char* what = "");
|
||||
44
kernel/pic.cpp
Normal file
44
kernel/pic.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "pic.h"
|
||||
|
||||
#include <kernel/kernio.h>
|
||||
|
||||
void PIC_Default_Remap() {
|
||||
outb(0x20, 0x11);
|
||||
outb(0xA0, 0x11);
|
||||
outb(0x21, 0x20);
|
||||
outb(0xA1, 0x28);
|
||||
outb(0x21, 0x04);
|
||||
outb(0xA1, 0x02);
|
||||
outb(0x21, 0x01);
|
||||
outb(0xA1, 0x01);
|
||||
outb(0x21, 0x0);
|
||||
outb(0xA1, 0x0);
|
||||
}
|
||||
|
||||
void PIC_Remap(int offset1, int offset2) {
|
||||
unsigned char a1, a2;
|
||||
|
||||
a1 = inb(PIC1_DATA); // save masks
|
||||
a2 = inb(PIC2_DATA);
|
||||
|
||||
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
|
||||
io_wait();
|
||||
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||
io_wait();
|
||||
outb(PIC1_DATA, offset1); // ICW2: Master PIC vector offset
|
||||
io_wait();
|
||||
outb(PIC2_DATA, offset2); // ICW2: Slave PIC vector offset
|
||||
io_wait();
|
||||
outb(PIC1_DATA, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
|
||||
io_wait();
|
||||
outb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||
io_wait();
|
||||
|
||||
outb(PIC1_DATA, ICW4_8086);
|
||||
io_wait();
|
||||
outb(PIC2_DATA, ICW4_8086);
|
||||
io_wait();
|
||||
|
||||
outb(PIC1_DATA, a1); // restore saved masks.
|
||||
outb(PIC2_DATA, a2);
|
||||
}
|
||||
25
kernel/pic.h
Normal file
25
kernel/pic.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#define PIC1 0x20 /* IO base address for master PIC */
|
||||
#define PIC2 0xA0 /* IO base address for slave PIC */
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1+1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2+1)
|
||||
|
||||
#define PIC_EOI 0x20 /* End-of-interrupt command code */
|
||||
|
||||
#define ICW1_ICW4 0x01 /* ICW4 (not) needed */
|
||||
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||
|
||||
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||
|
||||
void PIC_Default_Remap();
|
||||
void PIC_Remap(int offset1, int offset2);
|
||||
14
kernel/segment.asm
Normal file
14
kernel/segment.asm
Normal file
@@ -0,0 +1,14 @@
|
||||
.global SEGMENTS_RELOAD
|
||||
|
||||
SEGMENTS_RELOAD:
|
||||
movw $0x10, %ax
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
movw %ax, %fs
|
||||
movw %ax, %gs
|
||||
movw %ax, %ss
|
||||
ljmp $0x08, $flush2
|
||||
|
||||
flush2:
|
||||
ret
|
||||
|
||||
26
lib/kernel/logger/logger.cpp
Normal file
26
lib/kernel/logger/logger.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "logger.h"
|
||||
|
||||
#include <kernel/drivers/terminal/terminal.h>
|
||||
|
||||
void loggerLog(char* str) {
|
||||
Write(" ");
|
||||
Writeln(str);
|
||||
}
|
||||
|
||||
void loggerOK(char* str) {
|
||||
Write("[");
|
||||
SetFGColour(VGA_BRIGHT_GREEN);
|
||||
Write(" OK ");
|
||||
SetFGColour(VGA_WHITE);
|
||||
Write("] ");
|
||||
Writeln(str);
|
||||
}
|
||||
|
||||
void loggerFailed(char* str) {
|
||||
Write("[");
|
||||
SetFGColour(VGA_BRIGHT_RED);
|
||||
Write("FAILED");
|
||||
SetFGColour(VGA_WHITE);
|
||||
Write("] ");
|
||||
Writeln(str);
|
||||
}
|
||||
8
lib/kernel/logger/logger.h
Normal file
8
lib/kernel/logger/logger.h
Normal file
@@ -0,0 +1,8 @@
|
||||
// [FAILED]
|
||||
// [ OK ]
|
||||
|
||||
#pragma once
|
||||
|
||||
void loggerLog(char* str);
|
||||
void loggerOK(char* str);
|
||||
void loggerFailed(char* str);
|
||||
@@ -30,7 +30,7 @@ void reverse(char *s) {
|
||||
}
|
||||
|
||||
|
||||
char* itoa(int n, char s[]) {
|
||||
char* itoa(int n, char* s) {
|
||||
int i = 0;
|
||||
bool isNegative = false;
|
||||
|
||||
@@ -58,3 +58,28 @@ char* itoa(int n, char s[]) {
|
||||
reverse(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
int hexlen(int n) {
|
||||
if (!n) return 1;
|
||||
|
||||
int ret = 0;
|
||||
for (; n; n >>= 4) {
|
||||
++ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* itohx(int n, char* s) {
|
||||
const char hex_lookup[] = "0123456789ABCDEF";
|
||||
int len = hexlen(n);
|
||||
|
||||
if (len & 1) {
|
||||
*s++ = '0';
|
||||
}
|
||||
s[len] = '\0';
|
||||
|
||||
for (--len; len >= 0; n >>= 4, --len) {
|
||||
s[len] = hex_lookup[n & 0xf];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
void swap(int* a, int* b);
|
||||
void reverse(char* s);
|
||||
char* itoa(int i, char s[] = "");
|
||||
char* itoa (int i, char* s = "");
|
||||
char* itohx(int i, char* s = "");
|
||||
|
||||
51
linux.bxrc
Normal file
51
linux.bxrc
Normal file
@@ -0,0 +1,51 @@
|
||||
# configuration file generated by Bochs
|
||||
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1
|
||||
#config_interface: win32config
|
||||
display_library: x, options="gui_debug"
|
||||
memory: host=2048, guest=2048
|
||||
romimage: file="/home/Ben/programming/OS/owos/build/OwOS.iso", address=0x0, options=none
|
||||
boot: cdrom
|
||||
floppy_bootsig_check: disabled=0
|
||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
ata0-master: type=cdrom, path="/home/Ben/programming/OS/owos/build/OwOS.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
||||
ata0-slave: type=none
|
||||
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
|
||||
ata1-master: type=none
|
||||
ata1-slave: type=none
|
||||
ata2: enabled=0
|
||||
ata3: enabled=0
|
||||
optromimage1: file=none
|
||||
optromimage2: file=none
|
||||
optromimage3: file=none
|
||||
optromimage4: file=none
|
||||
optramimage1: file=none
|
||||
optramimage2: file=none
|
||||
optramimage3: file=none
|
||||
optramimage4: file=none
|
||||
pci: enabled=1, chipset=i440fx
|
||||
vga: extension=vbe, update_freq=5, realtime=1
|
||||
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU "
|
||||
cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0
|
||||
cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0
|
||||
cpuid: smep=0, smap=0, mwait=1, vmx=1
|
||||
print_timestamps: enabled=0
|
||||
port_e9_hack: enabled=0
|
||||
private_colormap: enabled=0
|
||||
clock: sync=none, time0=local, rtc_sync=0
|
||||
log: -
|
||||
logprefix: %t%e%d
|
||||
debug: action=ignore
|
||||
info: action=report
|
||||
error: action=report
|
||||
panic: action=ask
|
||||
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
|
||||
mouse: type=ps2, enabled=0, toggle=ctrl+mbutton
|
||||
sound: waveoutdrv=win, waveout=none, waveindrv=win, wavein=none, midioutdrv=win, midiout=none
|
||||
speaker: enabled=1, mode=sound
|
||||
parport1: enabled=1, file=none
|
||||
parport2: enabled=0
|
||||
com1: enabled=1, mode=null
|
||||
com2: enabled=0
|
||||
com3: enabled=0
|
||||
com4: enabled=0
|
||||
56
win32.bxrc
Normal file
56
win32.bxrc
Normal file
@@ -0,0 +1,56 @@
|
||||
# configuration file generated by Bochs
|
||||
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1
|
||||
config_interface: win32config
|
||||
display_library: win32, options="gui_debug"
|
||||
memory: host=32, guest=32
|
||||
romimage: file="C:\Program Files (x86)\Bochs-2.6.9/BIOS-bochs-latest", address=0x0, options=none
|
||||
vgaromimage: file="C:\Program Files (x86)\Bochs-2.6.9/VGABIOS-lgpl-latest"
|
||||
boot: cdrom
|
||||
floppy_bootsig_check: disabled=0
|
||||
# no floppya
|
||||
# no floppyb
|
||||
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||
ata0-master: type=cdrom, path="E:\OS\OwOS\build\OwOS.iso", status=inserted, model="Generic 1234", biosdetect=auto
|
||||
ata0-slave: type=none
|
||||
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
|
||||
ata1-master: type=none
|
||||
ata1-slave: type=none
|
||||
ata2: enabled=0
|
||||
ata3: enabled=0
|
||||
optromimage1: file=none
|
||||
optromimage2: file=none
|
||||
optromimage3: file=none
|
||||
optromimage4: file=none
|
||||
optramimage1: file=none
|
||||
optramimage2: file=none
|
||||
optramimage3: file=none
|
||||
optramimage4: file=none
|
||||
pci: enabled=1, chipset=i440fx
|
||||
vga: extension=vbe, update_freq=5, realtime=1
|
||||
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU "
|
||||
cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0
|
||||
cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0
|
||||
cpuid: smep=0, smap=0, mwait=1, vmx=1
|
||||
print_timestamps: enabled=0
|
||||
port_e9_hack: enabled=0
|
||||
private_colormap: enabled=0
|
||||
clock: sync=none, time0=local, rtc_sync=0
|
||||
# no cmosimage
|
||||
# no loader
|
||||
log: -
|
||||
logprefix: %t%e%d
|
||||
debug: action=ignore
|
||||
info: action=report
|
||||
error: action=report
|
||||
panic: action=ask
|
||||
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
|
||||
mouse: type=ps2, enabled=0, toggle=ctrl+mbutton
|
||||
sound: waveoutdrv=win, waveout=none, waveindrv=win, wavein=none, midioutdrv=win, midiout=none
|
||||
speaker: enabled=1, mode=sound
|
||||
parport1: enabled=1, file=none
|
||||
parport2: enabled=0
|
||||
com1: enabled=1, mode=null
|
||||
com2: enabled=0
|
||||
com3: enabled=0
|
||||
com4: enabled=0
|
||||
Reference in New Issue
Block a user