13using namespace MaxOS::system;
14using namespace MaxOS::memory;
15using namespace MaxOS::processes;
16using namespace MaxOS::common;
47 ASSERT(m_stack_pointer != 0 && m_tss_stack_pointer != 0,
"Failed to allocate stack for thread");
121 "movq (%%rsp), %%rax\n"
128 "movq %%r15, 0x00(%%rdi)\n"
129 "movq %%r14, 0x08(%%rdi)\n"
130 "movq %%r13, 0x10(%%rdi)\n"
131 "movq %%r12, 0x18(%%rdi)\n"
132 "movq %%r11, 0x20(%%rdi)\n"
133 "movq %%r10, 0x28(%%rdi)\n"
134 "movq %%r9, 0x30(%%rdi)\n"
135 "movq %%r8, 0x38(%%rdi)\n"
136 "movq %%rdi, 0x40(%%rdi)\n"
137 "movq %%rsi, 0x48(%%rdi)\n"
138 "movq %%rbp, 0x50(%%rdi)\n"
139 "movq %%rdx, 0x58(%%rdi)\n"
140 "movq %%rcx, 0x60(%%rdi)\n"
141 "movq %%rbx, 0x68(%%rdi)\n"
142 "movq %%rax, 0x70(%%rdi)\n"
145 "movq $0, 0x78(%%rdi)\n"
146 "movq $0, 0x80(%%rdi)\n"
149 "movq %%rax, 0x88(%%rdi)\n"
152 "xorq %%rax, %%rax\n"
154 "movq %%rax, 0x90(%%rdi)\n"
159 "movq %%rax, 0x98(%%rdi)\n"
162 "movq %%rsp, 0xA0(%%rdi)\n"
163 "xorq %%rax, %%rax\n"
165 "movq %%rax, 0xA8(%%rdi)\n"
171 :
"rax",
"cc",
"memory"
182: is_kernel(is_kernel),
240 for (
auto thread: m_threads)
261 m_threads.push_back(
thread);
262 thread->parent_pid = m_pid;
275 for (
uint32_t i = 0; i < m_threads.size(); i++) {
278 if (m_threads[i]->tid != tid)
286 m_threads.erase(m_threads.begin() + i);
306 for (
auto thread: m_threads)
339 for (
auto thread: m_threads)
static Logger DEBUG()
Gets active logger set to DEBUG level.
Stores the left, top, width and height of a rectangle.
void lock()
Lock the spinlock once it is available.
void unlock()
Unlock the spinlock.
Handles memory allocation and deallocation.
static MemoryManager * s_kernel_memory_manager
The memory manager for any kernel processes and all kernel allocations.
static void * malloc(size_t size)
Allocates a block of memory in the current USERSPACE heap.
static void * kmalloc(size_t size)
Allocates a block of memory in the KERNEL space.
static PhysicalMemoryManager * s_current_manager
The current physical memory manager in use.
Handles the loading and parsing of 64-bit ELF files.
A process that can be scheduled by the Scheduler, wraps & manages threads as well as its own address ...
uint64_t pid() const
Gets the pid of the process.
uint64_t total_ticks()
Gets the total ticks of the threads in the process (not this does not include any past killed threads...
string name
The name of the process.
common::Vector< Thread * > threads()
Gets the threads of the process.
void add_thread(Thread *thread)
Adds a thread to the process.
~Process()
Destructor for the Process class.
Process(const string &name, bool is_kernel=false)
Base Constructor for the Process.
bool is_kernel
Whether this process is a kernel process.
void set_pid(uint64_t pid)
Sets the pid of the process once added to the queue.
void remove_thread(uint64_t tid)
Remove a thread by its tid (NOTE: this will not remove it from the scheduler)
memory::MemoryManager * memory_manager
The manager for memory used by this process.
The execution context of a sub-process thread.
thread_state_t thread_state
The current state of the thread.
Thread(void(*_entry_point)(void *), void *args, int arg_amount, Process *parent)
Constructor for the Thread class.
uint64_t parent_pid
The parent process ID.
void save_sse_state()
Saves the SSE, x87 FPU, and MMX states from memory to the thread.
size_t wakeup_time
The time at which the thread should wake up (if sleeping)
~Thread()
Destructor for the Thread class.
void save_cpu_state()
Saves the CPU state into the thread's execution_state structure.
system::cpu_status_t execution_state
The CPU state of the thread.
void restore_sse_state()
Restores the SSE, x87 FPU, and MMX states from the thread to memory.
size_t ticks
The number of ticks the thread has run for.
void sleep(size_t milliseconds)
Sleeps the thread for a certain amount of time.
static Core * executing_core()
Gets the core that is currently executing.
Defines a Logger class for logging messages with different severity levels to multiple output streams...
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
void * memcpy(void *destination, const void *source, uint64_t num)
Copies a block of memory from one location to another.
Defines Process and Thread classes for managing processes and their execution contexts.
constexpr size_t STACK_SIZE
The size of the stack for each thread (4KB)