Logger and working GDT
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ Makefile
|
|||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
.vscode/
|
.vscode/
|
||||||
.vs/
|
.vs/
|
||||||
|
bx_enh_dbg.ini
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ file(GLOB DRIV_DISP_VGA "kernel/drivers/terminal/*.cpp" "kernel/drivers/termina
|
|||||||
|
|
||||||
# Lib source
|
# Lib source
|
||||||
file(GLOB LIB_STD "lib/std/*.cpp" "lib/std/*.asm")
|
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}
|
add_executable(OwOS ${KERN_SRC} ${KERN_LIB_SRC}
|
||||||
${DRIV_DISP_VGA}
|
${DRIV_DISP_VGA}
|
||||||
${LIB_STD})
|
${LIB_STD} ${LIB_KERN_LOG})
|
||||||
|
|
||||||
|
|
||||||
set_target_properties(OwOS PROPERTIES OUTPUT_NAME "OwOS.bin")
|
set_target_properties(OwOS PROPERTIES OUTPUT_NAME "OwOS.bin")
|
||||||
|
|
||||||
|
|||||||
56
bochsrc.bxrc
Normal file
56
bochsrc.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
|
||||||
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,10 +37,10 @@ _start:
|
|||||||
jmp 1b
|
jmp 1b
|
||||||
|
|
||||||
|
|
||||||
.global ASM_INIT_FPU
|
.global INIT_FPU
|
||||||
.type ASM_INIT_FPU, @function
|
.type INIT_FPU, @function
|
||||||
|
|
||||||
ASM_INIT_FPU:
|
INIT_FPU:
|
||||||
# FPU Config
|
# FPU Config
|
||||||
VAL_037F:
|
VAL_037F:
|
||||||
.hword 0x037F
|
.hword 0x037F
|
||||||
|
|||||||
41
kernel.cpp
41
kernel.cpp
@@ -1,10 +1,17 @@
|
|||||||
#include <lib/std/stdlib.h>
|
|
||||||
#include <kernel/multiboot.h>
|
#include <kernel/multiboot.h>
|
||||||
#include <lib/kernel/logger/logger.h>
|
|
||||||
#include <kernel/drivers/terminal/terminal.h>
|
#include <kernel/drivers/terminal/terminal.h>
|
||||||
|
#include <kernel/kernio.h>
|
||||||
|
#include <kernel/gdt.h>
|
||||||
|
|
||||||
|
#include <lib/std/stdlib.h>
|
||||||
|
#include <lib/std/memory.h>
|
||||||
|
#include <lib/kernel/logger/logger.h>
|
||||||
|
|
||||||
|
#define BochsBreak() outw(0x8A00,0x8A00); outw(0x8A00,0x08AE0);
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern void ASM_INIT_FPU(void);
|
extern void INIT_FPU(void);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -13,23 +20,29 @@ int kernel_main(uint32_t magic, multibootInfo_t* multiboot) {
|
|||||||
cls();
|
cls();
|
||||||
showCursor();
|
showCursor();
|
||||||
setFGColour(VGA_GREEN);
|
setFGColour(VGA_GREEN);
|
||||||
write("OwOS V0.2 ");
|
writeln("OwOS V0.2 Starting Up...");
|
||||||
writeln("Starting Up...");
|
|
||||||
setFGColour(VGA_WHITE);
|
setFGColour(VGA_WHITE);
|
||||||
nline();
|
nline();
|
||||||
|
|
||||||
|
// Init systems
|
||||||
|
|
||||||
write("OwO, What's This? ");
|
initGDT();
|
||||||
write("*notices ");
|
loggerOK("GDT Loaded");
|
||||||
write(itoa(multiboot->mem_upper / 1024));
|
|
||||||
write("mb of ram*");
|
|
||||||
|
|
||||||
|
nline(); nline();
|
||||||
|
write("OwO, What's This?");
|
||||||
setFGColour(VGA_BRIGHT_MAGENTA);
|
setFGColour(VGA_BRIGHT_MAGENTA);
|
||||||
nline(); nline(); nline();
|
write(" *notices ");
|
||||||
|
write(itoa(multiboot->mem_upper / 1024));
|
||||||
|
writeln("mb of ram*");
|
||||||
ASM_INIT_FPU();
|
setFGColour(VGA_WHITE);
|
||||||
|
nline();
|
||||||
|
|
||||||
|
setFGColour(VGA_YELLOW);
|
||||||
|
writeln("Welcome to OwOS");
|
||||||
|
setFGColour(VGA_BRIGHT_MAGENTA);
|
||||||
write("~#");
|
write("~#");
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#include "gdt.h"
|
||||||
|
|
||||||
|
#include <kernel/kernio.h>
|
||||||
|
#include <lib/std/memory.h>
|
||||||
|
|
||||||
|
struct SegmentDescriptor_t {
|
||||||
|
uint16_t limit_0;
|
||||||
|
uint16_t base_0;
|
||||||
|
uint8_t base_1;
|
||||||
|
uint8_t access;
|
||||||
|
uint8_t limit_1:4;
|
||||||
|
uint8_t flags:4;
|
||||||
|
uint8_t base_2;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
SegmentDescriptor_t _GDT[256];
|
||||||
|
|
||||||
|
void lgdt(void* GDT, uint16_t size) {
|
||||||
|
struct {
|
||||||
|
uint16_t size;
|
||||||
|
void* GDT;
|
||||||
|
} __attribute__((packed)) GDTR = { size, GDT };
|
||||||
|
|
||||||
|
asm ( "lgdt %0" : : "m"(GDTR) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void initGDT() {
|
||||||
|
memset(&_GDT, 0, sizeof(_GDT));
|
||||||
|
|
||||||
|
// Leave 0 blank for null segment
|
||||||
|
// Code Base 0 limit 32 Access EXEC + RW
|
||||||
|
setGDT(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
|
||||||
|
setGDT(2, 0x00000000, 0xFFFFFFFF, GDT_ACCESS_PRESENT | GDT_ACCESS_RW, GDT_FLAG_GR_PAGE | GDT_FLAG_SZ_32B);
|
||||||
|
|
||||||
|
lgdt(&_GDT, sizeof(_GDT));
|
||||||
|
SEGMENTS_RELOAD();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setGDT(uint32_t index, uint32_t baseAddr, uint32_t limitAddr, uint8_t accessLvl, uint8_t flags) {
|
||||||
|
if (index > 256) return;
|
||||||
|
_GDT[index].base_0 = (baseAddr >> 0) & 0xFFFF;
|
||||||
|
_GDT[index].base_1 = (baseAddr >> 16) & 0xFF;
|
||||||
|
_GDT[index].base_2 = (baseAddr>> 24) & 0xFF;
|
||||||
|
_GDT[index].limit_0 = (limitAddr >> 0) & 0xFFFF;
|
||||||
|
_GDT[index].limit_1 = (limitAddr >> 16) & 0x0F;
|
||||||
|
_GDT[index].access = accessLvl;
|
||||||
|
_GDT[index].flags = flags & 0x0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
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 initGDT();
|
||||||
|
void setGDT(uint32_t index, uint32_t baseAddr, uint32_t limitAddr, uint8_t accessLvl, uint8_t flags);
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
#include "kernio.h"
|
|
||||||
@@ -14,3 +14,33 @@ inline uint8_t inb(uint16_t port) {
|
|||||||
return ret;
|
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(void) {
|
||||||
|
/* TODO: This is probably fragile. */
|
||||||
|
asm ( "jmp 1f\n\t"
|
||||||
|
"1:jmp 2f\n\t"
|
||||||
|
"2:" );
|
||||||
|
}
|
||||||
|
|||||||
13
kernel/segment.asm
Normal file
13
kernel/segment.asm
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.global SEGMENTS_RELOAD
|
||||||
|
|
||||||
|
SEGMENTS_RELOAD:
|
||||||
|
ljmp $0x08, $reloadCS
|
||||||
|
|
||||||
|
reloadCS:
|
||||||
|
movw $0x10, %ax
|
||||||
|
movw %ax, %es
|
||||||
|
movw %ax, %ss
|
||||||
|
movw %ax, %ds
|
||||||
|
movw %ax, %fs
|
||||||
|
movw %ax, %gs
|
||||||
|
ret
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
// [FAILED]
|
// [FAILED]
|
||||||
// [ OK ]
|
// [ OK ]
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void loggerLog(char* str);
|
||||||
|
void loggerOK(char* str);
|
||||||
|
void loggerFailed(char* str);
|
||||||
|
|||||||
Reference in New Issue
Block a user