The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
arch_context_x86.c File Reference

x86 implementation of the arch-neutral context-switch helpers. More...

Functions

void isr_fork_return (void)
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.
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 with the parent's registers, except that the syscall returns 0 (and, for a thread, the user stack is its own).

Detailed Description

x86 implementation of the arch-neutral context-switch helpers.

arch_context_switch itself is pure assembly (context_switch.asm). the one piece that needs C is priming a brand-new kernel stack so that the first switch into a process "returns" into its entry function. that layout mirrors exactly what arch_context_switch pushes, so it lives next to the asm here.

Function Documentation

◆ isr_fork_return()

void isr_fork_return ( void )
extern

◆ arch_setup_initial_stack()

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.

entry_fn takes no arguments and never returns. on return, proc->kernel_esp points at the prepared stack.

Parameters
procthe process whose kernel stack to prime (uses kernel_stack).
entry_fnthe function the process should start running.

◆ arch_setup_fork_stack()

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 with the parent's registers, except that the syscall returns 0 (and, for a thread, the user stack is its own).

Parameters
childthe new process (uses kernel_stack, sets kernel_esp).
regsthe parent's saved user registers (its fork syscall frame).
user_spthe child's user stack pointer, or 0 for the parent's.