summaryrefslogtreecommitdiff
path: root/Source/Kernel/Linker
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/Linker')
-rw-r--r--Source/Kernel/Linker/Binary.proto.cpp19
-rw-r--r--Source/Kernel/Linker/Binary.proto.h16
-rw-r--r--Source/Kernel/Linker/MelonBinary.class.cpp30
-rw-r--r--Source/Kernel/Linker/MelonBinary.class.h21
4 files changed, 86 insertions, 0 deletions
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 <Linker/MelonBinary.class.h>
+
+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 <VFS/File.class.h>
+#include <TaskManager/Process.class.h>
+#include <TaskManager/Thread.class.h>
+
+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<u32int>(&magic);
+ if (magic == 0xFEEDBEEF) {
+ MelonBinary* r = new MelonBinary;
+ file.read<u32int>(&r->m_size);
+ file.read<u32int>(&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 <Linker/Binary.proto.h>
+
+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