mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:38:12 +00:00
ELFLoader works inside the kernel!
We load /_hello.o which just prints out a simple message. It executes inside the kernel itself, so no fancy userspace process or anything, but this is still so cool!
This commit is contained in:
parent
6ab0649ad6
commit
97e0d75bcb
10 changed files with 72 additions and 15 deletions
Binary file not shown.
7
Kernel/_hello.cpp
Normal file
7
Kernel/_hello.cpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
extern "C" int puts(const char*);
|
||||
|
||||
extern "C" int elf_entry()
|
||||
{
|
||||
puts("Home, where you are supposed to be...");
|
||||
return 0;
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
using namespace Userspace;
|
||||
|
||||
int elf_entry()
|
||||
extern "C" int elf_entry()
|
||||
{
|
||||
int fd = open("/Banner.txt");
|
||||
char buf[2048];
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <VirtualFileSystem/FileHandle.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include "MemoryManager.h"
|
||||
#include <ELFLoader/ELFLoader.h>
|
||||
|
||||
#if 0
|
||||
/* Keyboard LED disco task ;^) */
|
||||
|
@ -82,6 +83,8 @@ static void user_kprintf_main()
|
|||
DO_SYSCALL_A1(0x4000, 0);
|
||||
kprintf("This should not work!\n");
|
||||
HANG;
|
||||
for (;;) {
|
||||
}
|
||||
}
|
||||
|
||||
system_t system;
|
||||
|
@ -179,6 +182,25 @@ void init()
|
|||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
auto testExecutable = vfs->open("/_hello.o");
|
||||
ASSERT(testExecutable);
|
||||
auto testExecutableData = testExecutable->readEntireFile();
|
||||
ASSERT(testExecutableData);
|
||||
|
||||
ExecSpace space;
|
||||
space.loadELF(move(testExecutableData));
|
||||
auto* elf_entry = space.symbolPtr("elf_entry");
|
||||
ASSERT(elf_entry);
|
||||
|
||||
typedef int (*MainFunctionPtr)(void);
|
||||
kprintf("elf_entry: %p\n", elf_entry);
|
||||
int rc = reinterpret_cast<MainFunctionPtr>(elf_entry)();
|
||||
kprintf("it returned %d\n", rc);
|
||||
|
||||
HANG;
|
||||
}
|
||||
|
||||
// The idle task will spend its eternity here for now.
|
||||
for (;;) {
|
||||
asm("hlt");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue