Compare commits
No commits in common. "69b5cd001faca2943b42f02d6b2f7ce074c6a1f2" and "2eefda61143701d43bf97d2d871a0879b5e0ea63" have entirely different histories.
69b5cd001f
...
2eefda6114
|
@ -12,8 +12,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS True)
|
|||
add_subdirectory(zion)
|
||||
add_subdirectory(sys)
|
||||
|
||||
set(QEMU_CMD qemu-system-x86_64 -d guest_errors -m 1G -serial stdio -hda disk.img)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT disk.img
|
||||
COMMAND sudo sh ../scripts/build_image.sh disk.img
|
||||
|
@ -22,16 +20,11 @@ add_custom_command(
|
|||
)
|
||||
|
||||
add_custom_target(qemu
|
||||
COMMAND ${QEMU_CMD}
|
||||
COMMAND qemu-system-x86_64 -d guest_errors -m 1G -serial stdio -hda disk.img
|
||||
DEPENDS disk.img
|
||||
USES_TERMINAL)
|
||||
|
||||
add_custom_target(qemu-dbg
|
||||
COMMAND ${QEMU_CMD} -S -s
|
||||
DEPENDS disk.img
|
||||
USES_TERMINAL)
|
||||
|
||||
add_custom_target(qemu-int
|
||||
COMMAND ${QEMU_CMD} -d int
|
||||
COMMAND qemu-system-x86_64 -d guest_errors -m 1G -serial stdio -hda disk.img -S -s
|
||||
DEPENDS disk.img
|
||||
USES_TERMINAL)
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
|
||||
#include "zcall.h"
|
||||
#include "zerrors.h"
|
||||
|
||||
constexpr uint64_t prog2 = 0x00000020'00000000;
|
||||
|
||||
int main() {
|
||||
ZDebug("Testing");
|
||||
uint64_t err = ZProcessSpawn(0x100, prog2, 0x1000);
|
||||
if (err != Z_OK) {
|
||||
ZDebug("Error");
|
||||
} else {
|
||||
ZDebug("Return");
|
||||
}
|
||||
ZProcessSpawn(prog2, 0x1000);
|
||||
ZDebug("Return");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
|
||||
class Process;
|
||||
|
||||
class Capability {
|
||||
public:
|
||||
enum Type {
|
||||
UNDEFINED,
|
||||
PROCESS,
|
||||
};
|
||||
Capability(void* obj, Type type, uint64_t id, uint64_t permissions)
|
||||
: obj_(obj), type_(type), id_(id), permissions_(permissions) {}
|
||||
|
||||
template <typename T>
|
||||
T& obj();
|
||||
|
||||
uint64_t id() { return id_; }
|
||||
|
||||
bool CheckType(Type type) { return type_ == type; }
|
||||
|
||||
uint64_t permissions() { return permissions_; }
|
||||
bool HasPermissions(uint64_t requested) {
|
||||
return (permissions_ & requested) == requested;
|
||||
}
|
||||
|
||||
private:
|
||||
// FIXME: This should somehow be a shared ptr to keep the object alive.
|
||||
void* obj_;
|
||||
Type type_;
|
||||
uint64_t id_;
|
||||
uint64_t permissions_;
|
||||
};
|
||||
|
||||
template <class Process>
|
||||
Process& Capability::obj() {
|
||||
if (type_ != PROCESS) {
|
||||
panic("Accessing %u cap as object.", type_);
|
||||
}
|
||||
return *static_cast<Process*>(obj_);
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#include "debug/debug.h"
|
||||
|
||||
#include "common/port.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
#define COM1 0x3f8
|
||||
|
||||
|
@ -74,14 +73,7 @@ void MemToStr(uint64_t u, char* str) {
|
|||
str[18] = '\0';
|
||||
}
|
||||
|
||||
void AddProcPrefix() {
|
||||
if (gScheduler != nullptr) {
|
||||
auto& t = gScheduler->CurrentThread();
|
||||
dbg("[%u.%u] ", t.pid(), t.tid());
|
||||
}
|
||||
}
|
||||
|
||||
void dbg_internal(const char* fmt, va_list args) {
|
||||
void dbgln_internal(const char* fmt, va_list args) {
|
||||
for (; *fmt != '\0'; fmt++) {
|
||||
if (*fmt != '%') {
|
||||
dbgputchar(*fmt);
|
||||
|
@ -128,34 +120,24 @@ void dbg_internal(const char* fmt, va_list args) {
|
|||
}
|
||||
}
|
||||
}
|
||||
dbgputchar('\n');
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void dbg(const char* fmt, ...) {
|
||||
va_list arg;
|
||||
va_start(arg, fmt);
|
||||
dbg_internal(fmt, arg);
|
||||
va_end(arg);
|
||||
}
|
||||
|
||||
void dbgln(const char* fmt, ...) {
|
||||
AddProcPrefix();
|
||||
va_list arg;
|
||||
va_start(arg, fmt);
|
||||
dbg_internal(fmt, arg);
|
||||
dbgln_internal(fmt, arg);
|
||||
va_end(arg);
|
||||
dbgputchar('\n');
|
||||
}
|
||||
|
||||
void panic(const char* fmt, ...) {
|
||||
asm volatile("cli");
|
||||
AddProcPrefix();
|
||||
va_list arg;
|
||||
va_start(arg, fmt);
|
||||
dbg_internal(fmt, arg);
|
||||
dbgln_internal(fmt, arg);
|
||||
va_end(arg);
|
||||
dbgputchar('\n');
|
||||
dbgln("PANIC");
|
||||
while (1)
|
||||
;
|
||||
|
|
|
@ -2,6 +2,5 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
|
||||
void dbg(const char* fmt, ...);
|
||||
void dbgln(const char* str, ...);
|
||||
void panic(const char* str, ...);
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#define ZC_PROC_SPAWN_CHILD 0x1
|
|
@ -12,9 +12,8 @@ uint64_t ZDebug(const char* message);
|
|||
|
||||
// TODO: Move structs into an internal header.
|
||||
struct ZProcessSpawnReq {
|
||||
uint64_t cap_id;
|
||||
uint64_t elf_base;
|
||||
uint64_t elf_size;
|
||||
};
|
||||
|
||||
uint64_t ZProcessSpawn(uint64_t cap_id, uint64_t elf_base, uint64_t elf_size);
|
||||
uint64_t ZProcessSpawn(uint64_t elf_base, uint64_t elf_size);
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#define Z_OK 0x0
|
||||
#define ZE_NOT_FOUND 0x1
|
||||
#define ZE_INVALID 0x2
|
||||
#define ZE_DENIED 0x4
|
|
@ -1,7 +1,6 @@
|
|||
#include "scheduler/process.h"
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "include/cap_types.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "memory/physical_memory.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
@ -26,8 +25,6 @@ Process::Process() : id_(gNextId++), state_(RUNNING) {}
|
|||
void Process::CreateThread(uint64_t entry) {
|
||||
Thread* thread = new Thread(*this, next_thread_id_++, entry);
|
||||
threads_.PushBack(thread);
|
||||
caps_.PushBack(new Capability(this, Capability::PROCESS, next_cap_id_++,
|
||||
ZC_PROC_SPAWN_CHILD));
|
||||
gScheduler->Enqueue(thread);
|
||||
}
|
||||
|
||||
|
@ -53,15 +50,3 @@ void Process::CheckState() {
|
|||
}
|
||||
state_ = FINISHED;
|
||||
}
|
||||
|
||||
SharedPtr<Capability> Process::GetCapability(uint64_t cid) {
|
||||
auto iter = caps_.begin();
|
||||
while (iter != caps_.end()) {
|
||||
if (iter->id() == cid) {
|
||||
return *iter;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
dbgln("Bad cap access");
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/shared_ptr.h"
|
||||
#include "memory/virtual_memory.h"
|
||||
|
@ -27,7 +26,6 @@ class Process {
|
|||
void CreateThread(uint64_t entry);
|
||||
SharedPtr<Thread> GetThread(uint64_t tid);
|
||||
|
||||
SharedPtr<Capability> GetCapability(uint64_t cid);
|
||||
// Checks the state of all child threads and transitions to
|
||||
// finished if all have finished.
|
||||
void CheckState();
|
||||
|
@ -41,8 +39,6 @@ class Process {
|
|||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
uint64_t next_cap_id_ = 0x100;
|
||||
|
||||
LinkedList<SharedPtr<Thread>> threads_;
|
||||
LinkedList<SharedPtr<Capability>> caps_;
|
||||
};
|
||||
|
|
|
@ -41,14 +41,14 @@ Thread::Thread(Process& proc, uint64_t tid, uint64_t entry)
|
|||
uint64_t Thread::pid() const { return process_.id(); }
|
||||
|
||||
void Thread::Init() {
|
||||
dbgln("Thread start.", pid(), id_);
|
||||
dbgln("[%u.%u] thread start.", pid(), id_);
|
||||
uint64_t rsp = process_.vmm().AllocateUserStack();
|
||||
SetRsp0(rsp0_start_);
|
||||
jump_user_space(rip_, rsp);
|
||||
}
|
||||
|
||||
void Thread::Exit() {
|
||||
dbgln("Exiting", pid(), id_);
|
||||
dbgln("[%u.%u] Exiting", pid(), id_);
|
||||
state_ = FINISHED;
|
||||
process_.CheckState();
|
||||
gScheduler->Yield();
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "include/cap_types.h"
|
||||
#include "include/zcall.h"
|
||||
#include "include/zerrors.h"
|
||||
#include "loader/elf_loader.h"
|
||||
#include "scheduler/process.h"
|
||||
#include "scheduler/process_manager.h"
|
||||
|
@ -59,18 +57,6 @@ void InitSyscall() {
|
|||
}
|
||||
|
||||
uint64_t ProcessSpawn(ZProcessSpawnReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->cap_id);
|
||||
if (cap.empty()) {
|
||||
return ZE_NOT_FOUND;
|
||||
}
|
||||
if (!cap->CheckType(Capability::PROCESS)) {
|
||||
return ZE_INVALID;
|
||||
}
|
||||
|
||||
if (!cap->HasPermissions(ZC_PROC_SPAWN_CHILD)) {
|
||||
return ZE_DENIED;
|
||||
}
|
||||
dbgln("Proc spawn: %u:%u", req->elf_base, req->elf_size);
|
||||
SharedPtr<Process> proc = MakeShared<Process>();
|
||||
gProcMan->InsertProcess(proc);
|
||||
|
@ -87,7 +73,7 @@ extern "C" uint64_t SyscallHandler(uint64_t call_id, char* message) {
|
|||
panic("Returned from thread exit");
|
||||
break;
|
||||
case Z_DEBUG_PRINT:
|
||||
dbgln("[Debug] %s", message);
|
||||
dbgln("[%u.%u] [Debug] %s", thread.pid(), thread.tid(), message);
|
||||
break;
|
||||
case Z_PROCESS_SPAWN:
|
||||
return ProcessSpawn(reinterpret_cast<ZProcessSpawnReq*>(message));
|
||||
|
|
|
@ -12,9 +12,8 @@ uint64_t ZDebug(const char* message) {
|
|||
return SysCall1(Z_DEBUG_PRINT, message);
|
||||
}
|
||||
|
||||
uint64_t ZProcessSpawn(uint64_t cap_id, uint64_t elf_base, uint64_t elf_size) {
|
||||
uint64_t ZProcessSpawn(uint64_t elf_base, uint64_t elf_size) {
|
||||
ZProcessSpawnReq req{
|
||||
.cap_id = cap_id,
|
||||
.elf_base = elf_base,
|
||||
.elf_size = elf_size,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue