diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile index 17f4a621..58758c45 100644 --- a/libmaxsi/Makefile +++ b/libmaxsi/Makefile @@ -44,7 +44,7 @@ c/h/stdio.h COMMONOBJS=c++.o thread.o io.o memory.o string.o error.o format.o SORTIXOBJS:=$(addprefix sortix/,$(COMMONOBJS)) -LIBMAXSIOBJS:=$(COMMONOBJS) sortix-vga.o sortix-keyboard.o sortix-sound.o +LIBMAXSIOBJS:=$(COMMONOBJS) sortix-vga.o sortix-keyboard.o sortix-sound.o process.o HEADERS=\ error.h \ io.h \ @@ -53,6 +53,7 @@ platform.h \ string.h \ syscall.h \ thread.h \ +process.h \ types.h \ format.h \ keyboard.h \ diff --git a/libmaxsi/hsrc/process.h b/libmaxsi/hsrc/process.h new file mode 100644 index 00000000..381d05f3 --- /dev/null +++ b/libmaxsi/hsrc/process.h @@ -0,0 +1,37 @@ +/****************************************************************************** + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for + more details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + process.h + Exposes system calls for process creation and management. + +******************************************************************************/ + +#ifndef LIBMAXSI_PROCESS_H +#define LIBMAXSI_PROCESS_H + +namespace Maxsi +{ + namespace Process + { + int Execute(const char* filepath, int argc, const char** argv); + } +} + +#endif + diff --git a/libmaxsi/process.cpp b/libmaxsi/process.cpp new file mode 100644 index 00000000..5aa75267 --- /dev/null +++ b/libmaxsi/process.cpp @@ -0,0 +1,41 @@ +/****************************************************************************** + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for + more details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + process.cpp + Exposes system calls for process creation and management. + +******************************************************************************/ + +#include "platform.h" +#include "syscall.h" +#include "process.h" + +namespace Maxsi +{ + namespace Process + { + DEFN_SYSCALL3(int, SysExecute, 10, const char*, int, const char**); + + int Execute(const char* filepath, int argc, const char** argv) + { + return SysExecute(filepath, argc, argv); + } + } +} + diff --git a/sortix/process.cpp b/sortix/process.cpp index b14274aa..ce851bd9 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -26,6 +26,8 @@ #include #include "process.h" #include "memorymanagement.h" +#include "initrd.h" +#include "elf.h" namespace Sortix { @@ -75,4 +77,21 @@ namespace Sortix segments = NULL; } + + void SysExecute(CPU::InterruptRegisters* R) + { + const char* programname = (const char*) R->ebx; + size_t programsize = 0; + byte* program = InitRD::Open(programname, &programsize); + if ( program == NULL ) { R->eax = -1; return; } + addr_t entry = ELF::Construct(CurrentProcess(), program, programsize); + if ( entry == 0 ) + { + PanicF("Could not create process '%s'", programname); + } + + // This is a hacky way to set up the thread! + R->eip = entry; + R->useresp = 0x80000000UL; + } } diff --git a/sortix/process.h b/sortix/process.h index 471e0e0f..e4168be9 100644 --- a/sortix/process.h +++ b/sortix/process.h @@ -75,6 +75,8 @@ namespace Sortix }; Process* CurrentProcess(); + + void SysExecute(CPU::InterruptRegisters* R); } #endif diff --git a/sortix/syscall.cpp b/sortix/syscall.cpp index 091edbf1..020d12ac 100644 --- a/sortix/syscall.cpp +++ b/sortix/syscall.cpp @@ -34,6 +34,7 @@ #include "vga.h" #include "keyboard.h" #include "sound.h" +#include "process.h" namespace Sortix { @@ -50,7 +51,7 @@ namespace Sortix #endif } - const size_t NumSyscalls = 10; + const size_t NumSyscalls = 11; const Syscall Syscalls[NumSyscalls] = { &Scheduler::SysCreateThread, @@ -63,6 +64,7 @@ namespace Sortix &VGA::SysDeleteFrame, &Keyboard::SysReceieveKeystroke, &Sound::SysSetFrequency, + &SysExecute, }; void Init()