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:
parent
011addf46c
commit
2f9d08a800
6 changed files with 104 additions and 2 deletions
|
@ -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 \
|
||||
|
|
37
libmaxsi/hsrc/process.h
Normal file
37
libmaxsi/hsrc/process.h
Normal 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
41
libmaxsi/process.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@
|
|||
#include <libmaxsi/memory.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ namespace Sortix
|
|||
};
|
||||
|
||||
Process* CurrentProcess();
|
||||
|
||||
void SysExecute(CPU::InterruptRegisters* R);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue