77 lines
No EOL
2.2 KiB
C++
77 lines
No EOL
2.2 KiB
C++
#include <inttypes.h>
|
|
|
|
#include "console.hpp"
|
|
#include "pmm.hpp"
|
|
#include "numeric.hpp"
|
|
#include "pointer.hpp"
|
|
#include "multiboot.hpp"
|
|
#include "compat.h"
|
|
|
|
using namespace multiboot;
|
|
using namespace console_tools;
|
|
|
|
struct dummy;
|
|
|
|
// Symbols generated by linker, no useful content in there...
|
|
extern dummy kernelStartMarker;
|
|
extern dummy kernelEndMarker;
|
|
|
|
extern "C" void init(Structure const & data)
|
|
{
|
|
Console::main
|
|
<< "Hello World!\n"
|
|
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
|
|
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
|
|
<< "Hello default color.\n";
|
|
|
|
Console::main
|
|
<< "bootloader name: " << data.bootLoaderName << "\n"
|
|
<< "command line: " << data.commandline << "\n"
|
|
<< "count of modules: " << data.modules.length << "\n"
|
|
<< "count of mmaps: " << data.memoryMaps.length << "\n";
|
|
for(auto &mmap : data.memoryMaps) {
|
|
if(mmap.length == 0) {
|
|
continue;
|
|
}
|
|
Console::main
|
|
<< "mmap: "
|
|
<< "start: " << hex(mmap.base) << ", length: " << hex(mmap.length)
|
|
<< ", " << mmap.entry_size
|
|
<< ", " << sizeof(mmap)
|
|
<< ", free:" << mmap.isFree()
|
|
<< "\n";
|
|
if(mmap.base > 0xFFFFFFFF) {
|
|
Console::main << "mmap out of 4 gigabyte range." << "\n";
|
|
continue;
|
|
}
|
|
if(mmap.isFree()) {
|
|
// Mark all free memory free...
|
|
physical_t lower = physical_t(mmap.base).alignUpper(4096);
|
|
physical_t upper = physical_t(mmap.base + mmap.length).alignLower(4096);
|
|
|
|
uint32_t ptr = lower.numeric();
|
|
while (ptr < upper.numeric()) {
|
|
PMM::markFree(physical_t(ptr));
|
|
ptr += 0x1000;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mark all memory used by the kernel used...
|
|
physical_t lower = physical_t(&kernelStartMarker).alignLower(4096);
|
|
physical_t upper = physical_t(&kernelEndMarker).alignUpper(4096);
|
|
|
|
uint32_t ptr = lower.numeric();
|
|
while (ptr < upper.numeric()) {
|
|
PMM::markUsed(physical_t(ptr));
|
|
ptr += 0x1000;
|
|
}
|
|
|
|
for(int i = 0; i < 10; i++) {
|
|
bool success;
|
|
physical_t page = PMM::alloc(success);
|
|
Console::main << "allocated page " << i << " [" << success << "]: " << page << "\n";
|
|
}
|
|
}
|
|
|
|
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit."); |