The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
arch_context.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * arch-neutral kernel context switching.
5 *
6 * the scheduler drives multitasking through this interface without knowing
7 * how a given architecture saves registers or lays out a fresh kernel stack.
8 * each architecture supplies its own implementation.
9 */
10
11#include "common/stdint.h"
12
13struct process;
14typedef struct process process_t;
15struct registers;
16
17/**
18 * switch kernel execution from one process to another.
19 * saves the current callee-saved state on the current kernel stack, writes
20 * the resulting stack pointer into *old_sp, then loads new_sp and resumes
21 * whatever that stack was set up to run.
22 * @param old_sp where to store the outgoing process's kernel stack pointer.
23 * @param new_sp the incoming process's saved kernel stack pointer.
24 */
26
27/**
28 * prepare a process's kernel stack so its first arch_context_switch() into it
29 * begins executing entry_fn. entry_fn takes no arguments and never returns.
30 * on return, proc->kernel_esp points at the prepared stack.
31 * @param proc the process whose kernel stack to prime (uses kernel_stack).
32 * @param entry_fn the function the process should start running.
33 */
34void arch_setup_initial_stack(process_t *proc, void (*entry_fn)(void));
35
36/**
37 * prepare a forked child's kernel stack so its first arch_context_switch()
38 * into it returns to user mode with the parent's registers, except that
39 * the syscall returns 0 (and, for a thread, the user stack is its own).
40 * @param child the new process (uses kernel_stack, sets kernel_esp).
41 * @param regs the parent's saved user registers (its fork syscall frame).
42 * @param user_sp the child's user stack pointer, or 0 for the parent's.
43 */
44void arch_setup_fork_stack(process_t *child, const struct registers *regs, uintptr_t user_sp);
void arch_setup_fork_stack(process_t *child, const struct registers *regs, uintptr_t user_sp)
prepare a forked child's kernel stack so its first arch_context_switch() into it returns to user mode...
Definition arch_context_x86.c:48
void arch_context_switch(uintptr_t *old_sp, uintptr_t new_sp)
switch kernel execution from one process to another.
void arch_setup_initial_stack(process_t *proc, void(*entry_fn)(void))
prepare a process's kernel stack so its first arch_context_switch() into it begins executing entry_fn...
Definition arch_context_x86.c:20
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:19
struct process process_t
process control block.
process control block.
Definition process.h:69
saved register state pushed onto the stack by ISR stubs.
Definition isr.h:41