Cleans up OS initialization.
This commit is contained in:
parent
75b89dc1e0
commit
52a16fc519
2 changed files with 9 additions and 180 deletions
|
@ -10,12 +10,16 @@ KERNELS = $(filter-out lib%, $(PROJECTS))
|
|||
all: $(KERNELS) boot.img
|
||||
|
||||
.PHONY: $(PROJECTS)
|
||||
$(KERNELS): $(LIBS)
|
||||
$(KERNELS): dirs $(LIBS)
|
||||
make -C $@ $(ARGS)
|
||||
|
||||
$(LIBS):
|
||||
$(LIBS): dirs
|
||||
make -C $@ $(ARGS)
|
||||
|
||||
dirs:
|
||||
mkdir -p libs
|
||||
mkdir -p kernels
|
||||
|
||||
boot.img: $(PROJECTS)
|
||||
mformat -C -f 1440 -v VIDEO -i boot.img ::
|
||||
mcopy -i boot.img \
|
||||
|
|
|
@ -18,13 +18,6 @@
|
|||
#include <stdint.h>
|
||||
#include <new>
|
||||
|
||||
// #include <string.h>
|
||||
|
||||
/*
|
||||
namespace vm {
|
||||
#include <vm.h>
|
||||
}
|
||||
*/
|
||||
|
||||
using namespace multiboot;
|
||||
using namespace console_tools;
|
||||
|
@ -40,83 +33,6 @@ driver::Keyboard keyboardDriver;
|
|||
|
||||
VMMContext * kernelContext;
|
||||
|
||||
/*
|
||||
static const uint32_t entryPointAddress = 0x40000000;
|
||||
|
||||
void run_program0(Module const & module)
|
||||
{
|
||||
using namespace elf;
|
||||
|
||||
const Header *header = module.start.data<elf::Header>();
|
||||
|
||||
ProgramHeader *ph;
|
||||
int i;
|
||||
if (header->magic != MAGIC) {
|
||||
BSOD::die(Error::InvalidELFImage, "Keine gueltige ELF-Magic!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ph = (ProgramHeader*)(((char*) header) + header->ph_offset);
|
||||
for (i = 0; i < header->ph_entry_count; i++, ph++) {
|
||||
void* dest = (void*) ph->virt_addr;
|
||||
void* src = ((char*) header) + ph->offset;
|
||||
|
||||
// Nur Program Header vom Typ LOAD laden
|
||||
if (ph->type != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ph->virt_addr < entryPointAddress) {
|
||||
BSOD::die(Error::InvalidELFImage, "A LOAD section tried to sneak into the kernel!");
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < ph->mem_size; i += 0x1000) {
|
||||
kernelContext->provide(
|
||||
virtual_t(ph->virt_addr + i),
|
||||
VMMFlags::Writable | VMMFlags::UserSpace);
|
||||
}
|
||||
|
||||
memset(dest, 0, ph->mem_size);
|
||||
memcpy(dest, src, ph->file_size);
|
||||
}
|
||||
|
||||
using EntryPoint = void (*)();
|
||||
EntryPoint ep = (EntryPoint)entryPointAddress;
|
||||
ep();
|
||||
}
|
||||
|
||||
static void dump_elf(elf::Header *header)
|
||||
{
|
||||
using namespace elf;
|
||||
ProgramHeader *ph;
|
||||
int i;
|
||||
|
||||
// Ist es ueberhaupt eine ELF-Datei?
|
||||
if (header->magic != MAGIC) {
|
||||
BSOD::die(Error::InvalidELFImage, "Keine gueltige ELF-Magic!\n");
|
||||
return;
|
||||
}
|
||||
ph = (ProgramHeader*)(((char*) header) + header->ph_offset);
|
||||
for (i = 0; i < header->ph_entry_count; i++, ph++) {
|
||||
void* dest = (void*) ph->virt_addr;
|
||||
void* src = ((char*) header) + ph->offset;
|
||||
|
||||
Console::main
|
||||
<< "Header: " << ph->type << ", "
|
||||
<< "Source: " << src << ", "
|
||||
<< "Dest: " << dest << ", "
|
||||
<< "Memsize: " << ph->mem_size << ", "
|
||||
<< "Filesize: " << ph->file_size
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// static void strcpy(char *dst, const char *src)
|
||||
// {
|
||||
// while((*dst++ = *src++));
|
||||
// }
|
||||
|
||||
static void initializePMM(Structure const & data)
|
||||
{
|
||||
for(auto &mmap : data.memoryMaps) {
|
||||
|
@ -197,7 +113,6 @@ extern "C" void init(Structure const & data)
|
|||
IDT::initialize();
|
||||
Console::main << "Interrupts set up.\n";
|
||||
|
||||
/*
|
||||
Console::main << "Creating VMM Context...\n";
|
||||
kernelContext = new (PMM::alloc().data()) VMMContext();
|
||||
|
||||
|
@ -218,106 +133,16 @@ extern "C" void init(Structure const & data)
|
|||
Console::main << "Active Paging...\n";
|
||||
VMM::enable();
|
||||
Console::main << "Virtual Memory Management ready.\n";
|
||||
*/
|
||||
|
||||
timer.install();
|
||||
keyboardDriver.install();
|
||||
|
||||
Console::main << "Drivers installed.\n";
|
||||
|
||||
// ASM::sti();
|
||||
// Console::main << "Interrupts enabled.\n";
|
||||
ASM::sti();
|
||||
Console::main << "Interrupts enabled.\n";
|
||||
|
||||
/*
|
||||
if(data.modules.length > 0)
|
||||
{
|
||||
// Console::main << "ELF Modukle:\n";
|
||||
// dump_elf(data.modules[0].start.data<elf::Header>());
|
||||
// run_program0(data.modules[0]);
|
||||
|
||||
vm::Module module = {
|
||||
.code = reinterpret_cast<vm::Instruction*>(data.modules[0].start.data()),
|
||||
.length = data.modules[0].size() / sizeof(vm::Instruction),
|
||||
};
|
||||
|
||||
|
||||
Console::main << "Loaded instructions: " << module.length << "\n";
|
||||
|
||||
uint8_t page0[64];
|
||||
uint8_t page1[64];
|
||||
|
||||
strcpy((char*)page0, "Hallo Welt!\nDies ist die erste Ausgabe durch die VM.");
|
||||
|
||||
uint8_t *pages[2];
|
||||
pages[0] = page0;
|
||||
pages[1] = page1;
|
||||
|
||||
|
||||
vm::VirtualMemoryMap mmap = {
|
||||
.pageSize = 64,
|
||||
.length = 2,
|
||||
.pages = pages,
|
||||
};
|
||||
|
||||
vm::Process process = {
|
||||
.module = &module,
|
||||
.tag = (void*)1,
|
||||
.codePointer = 0,
|
||||
.stackPointer = 0,
|
||||
.basePointer = 0,
|
||||
.flags = 0,
|
||||
.stack = { 0 },
|
||||
.mmap = mmap,
|
||||
};
|
||||
|
||||
auto *p = &process;
|
||||
|
||||
while(vm::vm_step_process(p) && p->tag) {
|
||||
//Console::main << "?";
|
||||
// dump_proc(p);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
while(true);
|
||||
}
|
||||
|
||||
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
namespace vm
|
||||
{
|
||||
extern "C" void vm_assert(int assertion, const char *msg)
|
||||
{
|
||||
if(assertion != 0)
|
||||
return;
|
||||
BSOD::die(Error::VMError, msg);
|
||||
}
|
||||
|
||||
extern "C" void vm_syscall(Process *p, CommandInfo *info)
|
||||
{
|
||||
switch(info->additional)
|
||||
{
|
||||
case 0: // EXIT
|
||||
p->tag = NULL;
|
||||
break;
|
||||
case 1:
|
||||
Console::main << (char)info->input0;
|
||||
break;
|
||||
case 2:
|
||||
Console::main << info->input0;
|
||||
break;
|
||||
default:
|
||||
Console::main << "[SYSCALL " << info->additional << "]";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void vm_hwio(Process *p, CommandInfo *info)
|
||||
{
|
||||
BSOD::die(Error::VMError, "hwio not implemented yet.");
|
||||
}
|
||||
}
|
||||
*/
|
||||
static_assert(sizeof(void*) == 4, "Target platform is not 32 bit.");
|
Loading…
Reference in a new issue