summaryrefslogtreecommitdiff
path: root/Source/Kernel/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/Core')
-rw-r--r--Source/Kernel/Core/.kmain.wtf.cpp.swpbin0 -> 12288 bytes
-rw-r--r--Source/Kernel/Core/CMem.ns.cpp35
-rw-r--r--Source/Kernel/Core/CMem.ns.h15
-rw-r--r--Source/Kernel/Core/CMem.ns.obin0 -> 991 bytes
-rw-r--r--Source/Kernel/Core/Sys.ns.cpp66
-rw-r--r--Source/Kernel/Core/Sys.ns.h19
-rw-r--r--Source/Kernel/Core/Sys.ns.obin0 -> 1676 bytes
-rw-r--r--Source/Kernel/Core/common.wtf.h27
-rw-r--r--Source/Kernel/Core/cppsupport.wtf.cpp4
-rw-r--r--Source/Kernel/Core/cppsupport.wtf.obin0 -> 741 bytes
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp32
-rw-r--r--Source/Kernel/Core/kmain.wtf.obin0 -> 2948 bytes
-rw-r--r--Source/Kernel/Core/loader.wtf.asm59
-rw-r--r--Source/Kernel/Core/loader.wtf.obin0 -> 1312 bytes
-rw-r--r--Source/Kernel/Core/multiboot.wtf.h64
15 files changed, 321 insertions, 0 deletions
diff --git a/Source/Kernel/Core/.kmain.wtf.cpp.swp b/Source/Kernel/Core/.kmain.wtf.cpp.swp
new file mode 100644
index 0000000..bc7a8c6
--- /dev/null
+++ b/Source/Kernel/Core/.kmain.wtf.cpp.swp
Binary files differ
diff --git a/Source/Kernel/Core/CMem.ns.cpp b/Source/Kernel/Core/CMem.ns.cpp
new file mode 100644
index 0000000..c2129ec
--- /dev/null
+++ b/Source/Kernel/Core/CMem.ns.cpp
@@ -0,0 +1,35 @@
+#include <Core/common.wtf.h>
+
+namespace CMem {
+
+//Standard C functions
+u8int *memcpy(u8int *dest, const u8int *src, int count) {
+ for (int i = 0; i < count; i++) {
+ dest[i] = src[i];
+ }
+ return dest;
+}
+
+u8int *memset(u8int *dest, u8int val, int count) {
+ for (int i = 0; i < count; i++) {
+ dest[i] = val;
+ }
+ return dest;
+}
+
+u16int *memsetw(u16int *dest, u16int val, int count) {
+ for (int i = 0; i < count; i++) {
+ dest[i] = val;
+ }
+ return dest;
+}
+
+u32int strlen(const char *str) {
+ u32int i = 0;
+ while (str[i]) {
+ i++;
+ }
+ return i;
+}
+
+}
diff --git a/Source/Kernel/Core/CMem.ns.h b/Source/Kernel/Core/CMem.ns.h
new file mode 100644
index 0000000..98e0b10
--- /dev/null
+++ b/Source/Kernel/Core/CMem.ns.h
@@ -0,0 +1,15 @@
+#ifdef DEF_COMMON
+
+#ifndef DEF_CMEM_NS_H
+#define DEF_CMEM_NS_H
+
+namespace CMem {
+ u8int *memcpy(u8int *dest, const u8int *src, int count);
+ u8int *memset(u8int *dest, u8int val, int count);
+ u16int *memsetw(u16int *dest, u16int val, int count);
+ u32int strlen(const char *str);
+}
+
+#endif
+
+#endif
diff --git a/Source/Kernel/Core/CMem.ns.o b/Source/Kernel/Core/CMem.ns.o
new file mode 100644
index 0000000..b8b6dbb
--- /dev/null
+++ b/Source/Kernel/Core/CMem.ns.o
Binary files differ
diff --git a/Source/Kernel/Core/Sys.ns.cpp b/Source/Kernel/Core/Sys.ns.cpp
new file mode 100644
index 0000000..eca826f
--- /dev/null
+++ b/Source/Kernel/Core/Sys.ns.cpp
@@ -0,0 +1,66 @@
+//This automatically includes Sys.ns.h
+#include <Core/common.wtf.h>
+
+using namespace CMem;
+
+namespace Sys {
+
+void outb (u16int port, u8int value) {
+ asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));
+}
+
+u8int inb (u16int port) {
+ u8int ret;
+ asm volatile ("inb %1, %0" : "=a" (ret) : "dN" (port));
+ return ret;
+}
+
+u16int inw (u16int port) {
+ u16int ret;
+ asm volatile ("inw %1, %0" : "=a" (ret) : "dN" (port));
+ return ret;
+}
+
+//Used by DEBUG() macro (see common.wtf.h)
+void bochs_output(char *message, char *file, u32int line) {
+ for (u32int i = 0; i < strlen(message); i++) {
+ outb(0xE9, message[i]);
+ }
+ char* t = (char*)" (in ";
+ for (u32int i = 0; i < strlen(t); i++) {
+ outb(0xE9, t[i]);
+ }
+ for (u32int i = 0; i < strlen(file); i++) {
+ outb(0xE9, file[i]);
+ }
+ outb(0xE9, ')');
+ outb(0xE9, '\n');
+}
+
+//TODO : make PANIC output a visible message
+
+//Used by PANIC() macro (see common.wtf.h)
+void panic(char *message, char *file, u32int line) {
+ asm volatile("cli");
+
+ bochs_output("PANIC : ", file, 0);
+ bochs_output(message, file, 0);
+
+ while (1); //Enter infinite loop for halt
+}
+
+//Used by ASSERT() macro (see common.wtf.h)
+void panic_assert(char *file, u32int line, char *desc) {
+ asm volatile("cli");
+
+ bochs_output("ASSERTION FAILED : ", file, 0);
+ bochs_output(desc, file, 0);
+
+ while (1); //Enter infinite loop for halt
+}
+
+void reboot() {
+ outb(0x64, 0xFE);
+}
+
+}
diff --git a/Source/Kernel/Core/Sys.ns.h b/Source/Kernel/Core/Sys.ns.h
new file mode 100644
index 0000000..9a2975e
--- /dev/null
+++ b/Source/Kernel/Core/Sys.ns.h
@@ -0,0 +1,19 @@
+#ifdef DEF_COMMON
+//This must be included by common.wtf.h
+
+#ifndef DEF_SYS_NS_H
+#define DEF_SYS_NS_H
+
+namespace Sys {
+ void outb(u16int port, u8int value);
+ u8int inb(u16int port);
+ u16int inw(u16int port);
+ void panic(char* message, char *file, u32int line);
+ void panic_assert(char* file, u32int line, char *desc);
+ void bochs_output(char* message, char *file, u32int line);
+ void reboot();
+}
+
+#endif
+
+#endif
diff --git a/Source/Kernel/Core/Sys.ns.o b/Source/Kernel/Core/Sys.ns.o
new file mode 100644
index 0000000..58f3dc8
--- /dev/null
+++ b/Source/Kernel/Core/Sys.ns.o
Binary files differ
diff --git a/Source/Kernel/Core/common.wtf.h b/Source/Kernel/Core/common.wtf.h
new file mode 100644
index 0000000..9b1bc7e
--- /dev/null
+++ b/Source/Kernel/Core/common.wtf.h
@@ -0,0 +1,27 @@
+#ifndef DEF_COMMON
+#define DEF_COMMON
+
+#include <Config.h>
+
+#define NULL 0
+
+typedef unsigned int u32int;
+typedef unsigned short u16int;
+typedef unsigned char u8int;
+typedef int s32int;
+typedef short s16int;
+typedef char s8int;
+
+#include <Core/CMem.ns.h>
+#include <Core/Sys.ns.h>
+
+#define PANIC(msg) Sys::panic(msg, __FILE__, __LINE__)
+#define ASSERT(b) ((b) ? (void)0 : Sys::panic_assert(__FILE__, __LINE__, #b))
+
+#ifdef OPT_DEBUG
+#define DEBUG(m) Sys::bochs_output(m, __FILE__, __LINE__)
+#else
+#define DEBUG(m)
+#endif
+
+#endif
diff --git a/Source/Kernel/Core/cppsupport.wtf.cpp b/Source/Kernel/Core/cppsupport.wtf.cpp
new file mode 100644
index 0000000..77feed3
--- /dev/null
+++ b/Source/Kernel/Core/cppsupport.wtf.cpp
@@ -0,0 +1,4 @@
+extern "C" void __cxa_pure_virtual() {}
+
+void *__dso_handle;
+extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; }
diff --git a/Source/Kernel/Core/cppsupport.wtf.o b/Source/Kernel/Core/cppsupport.wtf.o
new file mode 100644
index 0000000..4088bfb
--- /dev/null
+++ b/Source/Kernel/Core/cppsupport.wtf.o
Binary files differ
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
new file mode 100644
index 0000000..59fa45a
--- /dev/null
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -0,0 +1,32 @@
+#include <Core/common.wtf.h>
+#include <Core/multiboot.wtf.h>
+
+#include <Devices/Display/VGATextOutput.class.h>
+#include <DisplayManager/Disp.ns.h>
+
+#include <Ressources/logo.cd>
+
+extern u32int end; //Placement address
+
+extern "C" void kmain(multiboot_info_t* mbd, u32int magic);
+
+void kmain(multiboot_info_t* mbd, u32int magic) {
+ DEBUG("Entering kmain.");
+
+ VGATextOutput vgaout;
+
+ Disp::setDisplay(&vgaout);
+
+ for (int i = 0; i < melonLogoLines; i++) {
+ int startCol = (Disp::textCols() / 2) - (melonLogoCols / 2);
+ for (int j = 0; j < melonLogoCols; j++) {
+ Disp::putChar(i + 2, j + startCol, melonLogo[i][j], 0x07);
+ }
+ }
+
+ if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
+ PANIC("Error with multiboot header.");
+ }
+
+ while(1);
+}
diff --git a/Source/Kernel/Core/kmain.wtf.o b/Source/Kernel/Core/kmain.wtf.o
new file mode 100644
index 0000000..19a82cf
--- /dev/null
+++ b/Source/Kernel/Core/kmain.wtf.o
Binary files differ
diff --git a/Source/Kernel/Core/loader.wtf.asm b/Source/Kernel/Core/loader.wtf.asm
new file mode 100644
index 0000000..e5f5839
--- /dev/null
+++ b/Source/Kernel/Core/loader.wtf.asm
@@ -0,0 +1,59 @@
+global loader ; making entry point visible to linker
+extern kmain ; kmain is defined elsewhere
+
+; setting up the Multiboot header - see GRUB docs for details
+MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
+MEMINFO equ 1<<1 ; provide memory map
+FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
+MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
+CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
+
+section .text
+align 4
+MultiBootHeader:
+ dd MAGIC
+ dd FLAGS
+ dd CHECKSUM
+
+; reserve initial kernel stack space
+STACKSIZE equ 0x4000 ; that's 16k.
+
+extern start_ctors, end_ctors, start_dtors, end_dtors
+
+loader:
+ mov esp, stack+STACKSIZE ; set up the stack
+ push eax ; pass Multiboot magic number
+ push ebx ; pass Multiboot info structure
+
+static_ctors_loop:
+ mov ebx, start_ctors
+ jmp .test
+.body:
+ call [ebx]
+ add ebx,4
+.test:
+ cmp ebx, end_ctors
+ jb .body
+
+ call kmain ; call kernel proper
+
+ cli
+
+static_dtors_loop: ; useless, kernel should never return
+ mov ebx, start_dtors
+ jmp .test
+.body:
+ call [ebx]
+ add ebx,4
+.test:
+ cmp ebx, end_dtors
+ jb .body
+
+hang:
+ hlt ; halt machine should kernel return
+ jmp hang
+
+section .bss
+align 32
+stack:
+ resb STACKSIZE ; reserve 16k stack on a quadword boundary
diff --git a/Source/Kernel/Core/loader.wtf.o b/Source/Kernel/Core/loader.wtf.o
new file mode 100644
index 0000000..caed8f0
--- /dev/null
+++ b/Source/Kernel/Core/loader.wtf.o
Binary files differ
diff --git a/Source/Kernel/Core/multiboot.wtf.h b/Source/Kernel/Core/multiboot.wtf.h
new file mode 100644
index 0000000..9771893
--- /dev/null
+++ b/Source/Kernel/Core/multiboot.wtf.h
@@ -0,0 +1,64 @@
+#ifndef HDR_MULTIBOOT
+#define HDR_MULTIBOOT
+#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
+#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
+
+struct multiboot_header_t{
+ unsigned long magic;
+ unsigned long flags;
+ unsigned long checksum;
+ unsigned long header_addr;
+ unsigned long load_addr;
+ unsigned long load_end_addr;
+ unsigned long bss_end_addr;
+ unsigned long entry_addr;
+};
+
+struct aout_symbol_table_t {
+ unsigned long tabsize;
+ unsigned long strsize;
+ unsigned long addr;
+ unsigned long reserved;
+};
+
+struct elf_section_header_table_t {
+ unsigned long num;
+ unsigned long size;
+ unsigned long addr;
+ unsigned long shndx;
+};
+
+struct multiboot_info_t {
+ unsigned long flags;
+ unsigned long mem_lower;
+ unsigned long mem_upper;
+ unsigned long boot_device;
+ unsigned long cmdline;
+ unsigned long mods_count;
+ unsigned long mods_addr;
+ union {
+ aout_symbol_table_t aout_sym;
+ elf_section_header_table_t elf_sec;
+ } u;
+ unsigned long mmap_length;
+ unsigned long mmap_addr;
+};
+
+struct module_t {
+ unsigned long mod_start;
+ unsigned long mod_end;
+ unsigned long string;
+ unsigned long reserved;
+};
+
+struct memory_map_t {
+ unsigned long size;
+ unsigned long base_addr_low;
+ unsigned long base_addr_high;
+ unsigned long length_low;
+ unsigned long length_high;
+ unsigned long type;
+};
+
+#endif
+