diff options
author | Alexis211 <alexis211@gmail.com> | 2009-08-22 21:44:32 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-08-22 21:44:32 +0200 |
commit | 2582a11c37ccc22d64974b20b0793e5ba873fe1f (patch) | |
tree | 485565c0950f0355290690d3396bcb4c22774fd0 /Source/Kernel/Core | |
parent | 74e721676ddd5d996ccf2e1d35da57320f658609 (diff) | |
download | Melon-2582a11c37ccc22d64974b20b0793e5ba873fe1f.tar.gz Melon-2582a11c37ccc22d64974b20b0793e5ba873fe1f.zip |
Lots of stuff added : heap, timer, device managment, ...
Diffstat (limited to 'Source/Kernel/Core')
-rw-r--r-- | Source/Kernel/Core/.kmain.wtf.cpp.swp | bin | 12288 -> 12288 bytes | |||
-rw-r--r-- | Source/Kernel/Core/CMem.ns.h | 2 | ||||
-rw-r--r-- | Source/Kernel/Core/Sys.ns.cpp | 16 | ||||
-rw-r--r-- | Source/Kernel/Core/Sys.ns.h | 3 | ||||
-rw-r--r-- | Source/Kernel/Core/common.wtf.h | 4 | ||||
-rw-r--r-- | Source/Kernel/Core/cppsupport.wtf.cpp | 6 | ||||
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 67 | ||||
-rw-r--r-- | Source/Kernel/Core/loader.wtf.asm | 31 |
8 files changed, 99 insertions, 30 deletions
diff --git a/Source/Kernel/Core/.kmain.wtf.cpp.swp b/Source/Kernel/Core/.kmain.wtf.cpp.swp Binary files differindex bf1668b..27008ec 100644 --- a/Source/Kernel/Core/.kmain.wtf.cpp.swp +++ b/Source/Kernel/Core/.kmain.wtf.cpp.swp diff --git a/Source/Kernel/Core/CMem.ns.h b/Source/Kernel/Core/CMem.ns.h index 98e0b10..f0c15da 100644 --- a/Source/Kernel/Core/CMem.ns.h +++ b/Source/Kernel/Core/CMem.ns.h @@ -3,6 +3,8 @@ #ifndef DEF_CMEM_NS_H #define DEF_CMEM_NS_H +//This namespace contains basic memory managment functions + namespace CMem { u8int *memcpy(u8int *dest, const u8int *src, int count); u8int *memset(u8int *dest, u8int val, int count); diff --git a/Source/Kernel/Core/Sys.ns.cpp b/Source/Kernel/Core/Sys.ns.cpp index 361dda6..5cd1c28 100644 --- a/Source/Kernel/Core/Sys.ns.cpp +++ b/Source/Kernel/Core/Sys.ns.cpp @@ -2,7 +2,7 @@ #include <Core/common.wtf.h> #include <VTManager/VirtualTerminal.class.h> -#define DEBUGVT(x) VirtualTerminal *x = new VirtualTerminal(5, 46, 0, 15); x->map(); x->put('\n'); +#define DEBUGVT(x) VirtualTerminal *x = new VirtualTerminal(4, 46, 0, 15); x->map(); x->put('\n'); using namespace CMem; @@ -40,7 +40,15 @@ void bochs_output(char *message, char *file, u32int line) { outb(0xE9, '\n'); } -//TODO : make PANIC output a visible message +void bochs_output_hex(u32int i) { + char hexdigits[] = "0123456789ABCDEF"; + outb(0xE9, '0'); + outb(0xE9, 'x'); + for (u32int j = 0; j < 8; j++) { + outb(0xE9, hexdigits[(i & 0xF0000000) >> 28]); + i = i << 4; + } +} //Used by PANIC() macro (see common.wtf.h) void panic(char *message, char *file, u32int line) { @@ -49,7 +57,7 @@ void panic(char *message, char *file, u32int line) { DEBUGVT(vt); bochs_output("PANIC : ", file, line); bochs_output(message, file, 0); - *vt << " PANIC : " << message << "\n In " << file << ":" << (s32int)line << "\n"; + *vt << " PANIC : " << message << "\n In " << file << ":" << (s32int)line; while (1) asm volatile("hlt"); //Enter infinite loop for halt } @@ -61,7 +69,7 @@ void panic_assert(char *file, u32int line, char *desc) { DEBUGVT(vt); bochs_output("ASSERTION FAILED : ", file, line); bochs_output(desc, file, 0); - *vt << " ASSERTION FAILED : " << desc << "\n In " << file << ":" << (s32int)line << "\n"; + *vt << " ASSERTION FAILED : " << desc << "\n In " << file << ":" << (s32int)line; while (1) asm volatile("hlt"); //Enter infinite loop for halt } diff --git a/Source/Kernel/Core/Sys.ns.h b/Source/Kernel/Core/Sys.ns.h index 9a2975e..69dcc42 100644 --- a/Source/Kernel/Core/Sys.ns.h +++ b/Source/Kernel/Core/Sys.ns.h @@ -4,6 +4,8 @@ #ifndef DEF_SYS_NS_H #define DEF_SYS_NS_H +//This file contains system-relative functions + namespace Sys { void outb(u16int port, u8int value); u8int inb(u16int port); @@ -11,6 +13,7 @@ namespace Sys { 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 bochs_output_hex(u32int i); void reboot(); } diff --git a/Source/Kernel/Core/common.wtf.h b/Source/Kernel/Core/common.wtf.h index 617a73c..86b0d9e 100644 --- a/Source/Kernel/Core/common.wtf.h +++ b/Source/Kernel/Core/common.wtf.h @@ -3,6 +3,8 @@ #include <Config.h> +//This file is very important : it contains type definitions, macro definitions and new/delete implementations. + #define NULL 0 typedef unsigned int u32int; @@ -20,8 +22,10 @@ typedef char s8int; #ifdef OPT_DEBUG #define DEBUG(m) Sys::bochs_output(m, __FILE__, __LINE__) +#define DEBUG_HEX(m) Sys::bochs_output_hex(m); #else #define DEBUG(m) +#define DEBUG_HEX(m) #endif #include <MemoryManager/Mem.ns.h> diff --git a/Source/Kernel/Core/cppsupport.wtf.cpp b/Source/Kernel/Core/cppsupport.wtf.cpp index 77feed3..d495dff 100644 --- a/Source/Kernel/Core/cppsupport.wtf.cpp +++ b/Source/Kernel/Core/cppsupport.wtf.cpp @@ -1,4 +1,6 @@ -extern "C" void __cxa_pure_virtual() {} +//This file just contains a few methods required for some C++ things to work -void *__dso_handle; +extern "C" void __cxa_pure_virtual() {} //Required when using abstract classes + +void *__dso_handle; //Required when using global objects extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; } diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index e201a07..9e2004e 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -1,9 +1,18 @@ +//This file contains the kernel's main procedure + #include <Core/common.wtf.h> #include <Core/multiboot.wtf.h> #include <Devices/Display/VGATextOutput.class.h> -#include <DisplayManager/Disp.ns.h> +#include <Devices/Timer.class.h> +#include <DeviceManager/Disp.ns.h> +#include <DeviceManager/Dev.ns.h> #include <VTManager/VirtualTerminal.class.h> +#include <MemoryManager/PhysMem.ns.h> +#include <MemoryManager/PageAlloc.ns.h> +#include <MemoryManager/GDT.ns.h> +#include <SyscallManager/IDT.ns.h> +#include <Library/String.class.h> #include <Ressources/logo.cd> @@ -15,28 +24,68 @@ void kmain(multiboot_info_t* mbd, u32int magic) { DEBUG("Entering kmain."); Mem::placementAddress = (u32int)&end; + mbd->cmdline += 0xC0000000; mbd->mods_addr += 0xC0000000; //Take stuff into acount + module_t *mods = (module_t*)mbd->mods_addr; + for (u32int i = 0; i < mbd->mods_count; i++) { + mods[i].mod_start += 0xC0000000; + mods[i].mod_end += 0xC0000000; + if (mods[i].mod_end > Mem::placementAddress) + Mem::placementAddress = mods[i].mod_end + 0x1000; + } VGATextOutput *vgaout = new VGATextOutput(); Disp::setDisplay(vgaout); + if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { + PANIC("Error with multiboot header."); + } + + VirtualTerminal *melonLogoVT = new VirtualTerminal(melonLogoLines, melonLogoCols, 7, 0); 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); + melonLogoVT->putChar(i, j, melonLogo[i][j]); } } + melonLogoVT->map(2); VirtualTerminal *kvt = new VirtualTerminal(12, 40, 0, 2); kvt->map(melonLogoLines + 4); - *kvt << "Kernel initializing in HIGHER HALF!\n"; + *kvt << "* Kernel initializing in HIGHER HALF!\n"; - *kvt << "Lower ram : " << (s32int)mbd->mem_lower << "k, upper : " << (s32int)mbd->mem_upper << "k.\n"; + *kvt << "- Lower ram : " << (s32int)mbd->mem_lower << "k, upper : " << (s32int)mbd->mem_upper << "k.\n"; + *kvt << "- Kernel command line : " << (u32int)mbd->cmdline << "\n"; + *kvt << "- Modules@" << (u32int)mbd->mods_addr << ", mbd@" << (u32int)mbd << "\n"; + *kvt << "- Placement address : " << (u32int)Mem::placementAddress << "\n"; - if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { - PANIC("Error with multiboot header."); - } + *kvt << "> Loading IDT..."; + IDT::init(); + + *kvt << "OK.\n> Initializing paging..."; + u32int totalRam = ((mbd->mem_upper + 1024) * 1024); + PhysMem::initPaging(totalRam); + + *kvt << "OK.\n- Total ram : " << (s32int)(totalRam / 1024) << "k.\n"; + GDT::init(); + *kvt << "> GDT OK. Cleaning page directory..."; + PhysMem::removeTemporaryPages(); + + *kvt << "OK.\n> Creating heap..."; + Mem::createHeap(); + *kvt << "OK.\n"; + *kvt << "- Free frames : " << (s32int)PhysMem::free() << "/" << + (s32int)PhysMem::total(); + + *kvt << "\n> Registering vgaout..."; + Dev::registerDevice(vgaout); + + *kvt << "OK.\n> Initializing PIT..."; + Dev::registerDevice(new Timer()); + + *kvt << "OK.\n"; + + asm volatile("sti"); - while(1); + //PANIC("END OF KMAIN"); } diff --git a/Source/Kernel/Core/loader.wtf.asm b/Source/Kernel/Core/loader.wtf.asm index c5248e9..8d7b076 100644 --- a/Source/Kernel/Core/loader.wtf.asm +++ b/Source/Kernel/Core/loader.wtf.asm @@ -1,5 +1,5 @@ -global loader ; making entry point visible to linker -extern kmain ; kmain is defined elsewhere +[GLOBAL loader] ; making entry point visible to linker +[EXTERN kmain] ; kmain is defined in kmain.wtf.cpp ; setting up the Multiboot header - see GRUB docs for details MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries @@ -18,9 +18,9 @@ MultiBootHeader: ; reserve initial kernel stack space STACKSIZE equ 0x4000 ; that's 16k. -extern start_ctors, end_ctors, start_dtors, end_dtors +extern start_ctors, end_ctors, start_dtors, end_dtors ; these are required for global objects -loader: +loader: ;here, we load our false GDT, used for having the kernel in higher half lgdt [trickgdt] mov cx, 0x10; mov ds, cx; @@ -32,13 +32,14 @@ loader: jmp 0x08:higherhalf -higherhalf: +higherhalf: ; now we're running in higher half + mov esp, stack+STACKSIZE ; set up the stack push eax ; pass Multiboot magic number add ebx, 0xC0000000 ; update the MB info structure so that it is in the new seg. push ebx ; pass Multiboot info structure -static_ctors_loop: +static_ctors_loop: ; construct global objects mov ebx, start_ctors jmp .test .body: @@ -50,10 +51,10 @@ static_ctors_loop: call kmain ; call kernel proper - cli + cli ; disable interuptions static_dtors_loop: ; useless, kernel should never return - mov ebx, start_dtors + mov ebx, start_dtors ; destruct global objects jmp .test .body: call [ebx] @@ -66,16 +67,16 @@ hang: hlt ; halt machine should kernel return jmp hang -[section .setup] +[section .setup] ; this is included in the .setup section, so that it thinks it is at 0x00100000 -trickgdt: - dw gdt_end - gdt - 1 - dd gdt +trickgdt: ; our false GDT + dw gdt_end - gdt - 1 ; gdt limit + dd gdt ; gdt base gdt: - dd 0, 0 - db 0xFF, 0xFF, 0, 0, 0, 10011010b, 11001111b, 0x40 - db 0xFF, 0xFF, 0, 0, 0, 10010010b, 11001111b, 0x40 + dd 0, 0 ; null GDT entry + db 0xFF, 0xFF, 0, 0, 0, 10011010b, 11001111b, 0x40 ; kernel code segment + db 0xFF, 0xFF, 0, 0, 0, 10010010b, 11001111b, 0x40 ; kernel data segment gdt_end: |