From 22c06556ccbd07f4ef7da39a62d10e03fbee3fe0 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 18 Oct 2009 10:34:11 +0200 Subject: Loading binaries now is done through a much more unified interface. --- Source/Kernel/Linker/Binary.proto.cpp | 19 +++++++++++++++++++ Source/Kernel/Linker/Binary.proto.h | 16 ++++++++++++++++ Source/Kernel/Linker/MelonBinary.class.cpp | 30 ++++++++++++++++++++++++++++++ Source/Kernel/Linker/MelonBinary.class.h | 21 +++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 Source/Kernel/Linker/Binary.proto.cpp create mode 100644 Source/Kernel/Linker/Binary.proto.h create mode 100644 Source/Kernel/Linker/MelonBinary.class.cpp create mode 100644 Source/Kernel/Linker/MelonBinary.class.h (limited to 'Source/Kernel/Linker') diff --git a/Source/Kernel/Linker/Binary.proto.cpp b/Source/Kernel/Linker/Binary.proto.cpp new file mode 100644 index 0000000..6053f22 --- /dev/null +++ b/Source/Kernel/Linker/Binary.proto.cpp @@ -0,0 +1,19 @@ +#include "Binary.proto.h" + +#include + +Binary* (*loaders[])(File& file) = { + &MelonBinary::load, + +0 }; + +Binary* Binary::load(File& file) { + Binary* r = 0; + u32int i = 0; + while (loaders[i] != 0) { + r = loaders[i](file); //Call loader + if (r != 0) break; + i++; + } + return r; +} diff --git a/Source/Kernel/Linker/Binary.proto.h b/Source/Kernel/Linker/Binary.proto.h new file mode 100644 index 0000000..d0bd039 --- /dev/null +++ b/Source/Kernel/Linker/Binary.proto.h @@ -0,0 +1,16 @@ +#ifndef DEF_BINARY_PROTO_H +#define DEF_BINARY_PROTO_H + +#include +#include +#include + +class Binary { + public: + static Binary* load(File& file); + virtual ~Binary() {} + + virtual thread_entry_t toProcess(Process* p) = 0; +}; + +#endif diff --git a/Source/Kernel/Linker/MelonBinary.class.cpp b/Source/Kernel/Linker/MelonBinary.class.cpp new file mode 100644 index 0000000..d6074de --- /dev/null +++ b/Source/Kernel/Linker/MelonBinary.class.cpp @@ -0,0 +1,30 @@ +#include "MelonBinary.class.h" + +Binary* MelonBinary::load(File& file) { + u32int magic; + file.read(&magic); + if (magic == 0xFEEDBEEF) { + MelonBinary* r = new MelonBinary; + file.read(&r->m_size); + file.read(&r->m_org); + r->m_data = (u8int*)Mem::kalloc(r->m_size); + file.read(r->m_size, r->m_data); + return r; + } else { + return 0; + } +} + +MelonBinary::~MelonBinary() { + delete m_data; +} + +thread_entry_t MelonBinary::toProcess(Process* p) { + if (p == 0) return 0; + for (u32int i = m_org; i < m_org + m_size; i += 0x1000) { + p->getPagedir()->allocFrame(i, true, true); + } + p->getPagedir()->switchTo(); + memcpy((u8int*)m_org, m_data, m_size); + return (thread_entry_t)m_org; +} diff --git a/Source/Kernel/Linker/MelonBinary.class.h b/Source/Kernel/Linker/MelonBinary.class.h new file mode 100644 index 0000000..4300c7e --- /dev/null +++ b/Source/Kernel/Linker/MelonBinary.class.h @@ -0,0 +1,21 @@ +#ifndef DEF_MELONBINARY_CLASS_H +#define DEF_MELONBINARY_CLASS_H + +#include + +class MelonBinary : public Binary { + private: + u32int m_size; + u32int m_org; + u8int* m_data; + + MelonBinary() {} + + public: + virtual ~MelonBinary(); + static Binary* load(File& file); + + thread_entry_t toProcess(Process* p); +}; + +#endif -- cgit v1.2.3