From c73fc79260a99d79f3c93686d6b0f6906a286f7e Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 10 Mar 2014 19:02:50 +0100 Subject: [PATCH] Prepare some basic early logging support --- kernel/include/early_logging.hpp | 22 ++++++++++++++++++++++ kernel/src/boot/boot_16.cpp | 27 +++++++++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 kernel/include/early_logging.hpp diff --git a/kernel/include/early_logging.hpp b/kernel/include/early_logging.hpp new file mode 100644 index 00000000..757a7ebf --- /dev/null +++ b/kernel/include/early_logging.hpp @@ -0,0 +1,22 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include + +#ifndef EARLY_LOGGING_HPP +#define EARLY_LOGGING_HPP + +namespace early { + +constexpr const uint32_t MAX_EARLY_LOGGING = 128; + +extern uint32_t early_logs_count; +extern uint32_t early_logs[MAX_EARLY_LOGGING]; + +} //end of namespace early + +#endif \ No newline at end of file diff --git a/kernel/src/boot/boot_16.cpp b/kernel/src/boot/boot_16.cpp index 93dfa61e..a21aef6e 100644 --- a/kernel/src/boot/boot_16.cpp +++ b/kernel/src/boot/boot_16.cpp @@ -13,10 +13,14 @@ #include "gdt.hpp" #include "e820.hpp" //Just for the address of the e820 map #include "vesa.hpp" +#include "early_logging.hpp" //The Task State Segment gdt::task_state_segment_t gdt::tss; +uint32_t early::early_logs_count = 0; +uint32_t early::early_logs[early::MAX_EARLY_LOGGING]; + e820::bios_e820_entry e820::bios_e820_entries[e820::MAX_E820_ENTRIES]; int16_t e820::bios_e820_entry_count = 0; @@ -26,17 +30,25 @@ bool vesa::vesa_enabled = false; namespace { +/* Early Logging */ + +void early_log(const char* s){ + early::early_logs[early::early_logs_count++] = reinterpret_cast(s); +} + +/* VESA */ + constexpr const uint16_t DEFAULT_WIDTH = 1280; constexpr const uint16_t DEFAULT_HEIGHT = 1024; constexpr const uint16_t DEFAULT_BPP = 32; void out_byte(uint8_t value, uint16_t port){ - __asm__ __volatile__("out %1, %0" : : "a" (value), "dN" (port)); + asm volatile("out %1, %0" : : "a" (value), "dN" (port)); } uint8_t in_byte(uint16_t port){ uint8_t value; - __asm__ __volatile__("in %0,%1" : "=a" (value) : "dN" (port)); + asm volatile("in %0,%1" : "=a" (value) : "dN" (port)); return value; } @@ -74,9 +86,12 @@ int detect_memory_e820(){ : "a"(0xE820), "b"(contID), "c"(24), "d"(0x534D4150), "D"(&buf)); if (signature != 0x534D4150){ + early_log("e820 failed"); return -1; } + early_log("Found e820 entry"); + if (bytes > 20 && (smap->acpi & 0x0001) == 0){ // ignore this entry } else { @@ -199,7 +214,7 @@ void setup_vesa(){ } void disable_interrupts(){ - __asm__ __volatile__ ("cli"); + asm volatile ("cli"); } void enable_a20_gate(){ @@ -400,15 +415,15 @@ void __attribute__ ((noreturn)) rm_main(){ //Make sure segments are clean reset_segments(); + //Enable VESA + setup_vesa(); + //Analyze memory detect_memory(); //Make sure a20 gate is enabled enable_a20_gate(); - //Enable VESA - setup_vesa(); - //Disable interrupts disable_interrupts();