1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Added a process execute API.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-27 20:57:39 +02:00
parent 011addf46c
commit 2f9d08a800
6 changed files with 104 additions and 2 deletions

View file

@ -44,7 +44,7 @@ c/h/stdio.h
COMMONOBJS=c++.o thread.o io.o memory.o string.o error.o format.o COMMONOBJS=c++.o thread.o io.o memory.o string.o error.o format.o
SORTIXOBJS:=$(addprefix sortix/,$(COMMONOBJS)) 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=\ HEADERS=\
error.h \ error.h \
io.h \ io.h \
@ -53,6 +53,7 @@ platform.h \
string.h \ string.h \
syscall.h \ syscall.h \
thread.h \ thread.h \
process.h \
types.h \ types.h \
format.h \ format.h \
keyboard.h \ keyboard.h \

37
libmaxsi/hsrc/process.h Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
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

41
libmaxsi/process.cpp Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
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);
}
}
}

View file

@ -26,6 +26,8 @@
#include <libmaxsi/memory.h> #include <libmaxsi/memory.h>
#include "process.h" #include "process.h"
#include "memorymanagement.h" #include "memorymanagement.h"
#include "initrd.h"
#include "elf.h"
namespace Sortix namespace Sortix
{ {
@ -75,4 +77,21 @@ namespace Sortix
segments = NULL; 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;
}
} }

View file

@ -75,6 +75,8 @@ namespace Sortix
}; };
Process* CurrentProcess(); Process* CurrentProcess();
void SysExecute(CPU::InterruptRegisters* R);
} }
#endif #endif

View file

@ -34,6 +34,7 @@
#include "vga.h" #include "vga.h"
#include "keyboard.h" #include "keyboard.h"
#include "sound.h" #include "sound.h"
#include "process.h"
namespace Sortix namespace Sortix
{ {
@ -50,7 +51,7 @@ namespace Sortix
#endif #endif
} }
const size_t NumSyscalls = 10; const size_t NumSyscalls = 11;
const Syscall Syscalls[NumSyscalls] = const Syscall Syscalls[NumSyscalls] =
{ {
&Scheduler::SysCreateThread, &Scheduler::SysCreateThread,
@ -63,6 +64,7 @@ namespace Sortix
&VGA::SysDeleteFrame, &VGA::SysDeleteFrame,
&Keyboard::SysReceieveKeystroke, &Keyboard::SysReceieveKeystroke,
&Sound::SysSetFrequency, &Sound::SysSetFrequency,
&SysExecute,
}; };
void Init() void Init()