acadia/zion/scheduler/thread.h
Drew Galbraith b9b45c5e45 Add the ability to copy memory to non resident process.
Use/Test this by loading the user space elf from the kernel process
before it starts rather than as a part of the first thread.

This simplifies thread start a fair bit.
2023-05-30 01:27:47 -07:00

54 lines
1.2 KiB
C++

#pragma once
#include <stdint.h>
#include "lib/shared_ptr.h"
// Forward decl due to cyclic dependency.
class Process;
class Thread {
public:
enum State {
UNSPECIFIED,
RUNNING,
RUNNABLE,
FINISHED,
};
static SharedPtr<Thread> RootThread(Process* root_proc);
explicit Thread(const SharedPtr<Process>& proc, uint64_t tid, uint64_t entry);
uint64_t tid() { return id_; };
uint64_t pid();
Process& process() { return *process_; }
uint64_t* Rsp0Ptr() { return &rsp0_; }
uint64_t Rsp0Start() { return rsp0_start_; }
// Called the first time the thread starts up.
void Init();
// State Management.
State GetState() { return state_; };
void SetState(State state) { state_ = state; }
void Exit();
private:
// Special constructor for the root thread only.
Thread(Process* proc) : process_(proc), id_(0) {}
SharedPtr<Process> process_;
uint64_t id_;
State state_ = RUNNABLE;
// Startup Context for the thread.
uint64_t rip_;
// Stack pointer to take on resume.
// Stack will contain the full thread context.
uint64_t rsp0_;
// Stack pointer to take when returning from userspace.
// I don't think me mind clobbering the stack here.
uint64_t rsp0_start_;
};