| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /* Preemptive round-robin multitasking for i586, ring-0 only. */
- #ifndef PROCESS_H
- #define PROCESS_H
- #define PROC_STACK_SIZE 0x1000 /* 4 KB per process (= 1 page) */
- /* Process stacks are allocated from the frame allocator (mm.c), i.e. above the
- * VGA shadow buffer. If a page is unavailable we fall back to a small static
- * pool in BSS so the system still boots with fewer processes. */
- #define PROC_FALLBACK_STACK_MAX 8
- #define PROC_UNUSED 0
- #define PROC_READY 1
- #define PROC_RUNNING 2
- #define PROC_DEAD 3
- #define PROC_SLEEPING 4
- #define TIMESLICE_TICKS 20 /* context switch every 20 ms (PIT @ 1 kHz) */
- #define PROC_NAME_LEN 12
- #define PROC_CWD_MAX 64
- struct text_screen; /* forward decl (see screen.h) */
- struct sys_procinfo; /* forward decl (see syscall.h; `top` snapshot) */
- struct surface; /* forward decl (see vga.h; render target override) */
- struct process {
- unsigned int esp;
- unsigned int state;
- unsigned int pid;
- char name[PROC_NAME_LEN];
- struct text_screen *screen; /* output target for io_putchar & co. */
- unsigned int stack_base; /* page to free on exit, or 0 (bootstrap/fallback) */
- unsigned int cr3; /* physical address of this process's page dir */
- unsigned int kstack_top; /* ring-0 stack top (for TSS esp0) */
- unsigned int wake_ms; /* tick deadline when PROC_SLEEPING */
- char cwd[PROC_CWD_MAX]; /* working directory (ring-3 commands) */
- /* CPU accounting for `top`. switch.S credits the running process on
- * every PIT tick, so the layout after cwd must match PCB_CPU_TICKS /
- * PCB_SIZE there (see the _Static_assert in process.c). */
- unsigned int cpu_ticks; /* ticks spent as the running process */
- unsigned int start_ticks; /* get_ticks_ms() at creation */
- /* Render target override: 0 = the screen. Set while the window manager
- * draws into a layer, so another process's drawing can never land in
- * it. Kept before tty so the PIT hot path offsets stay put. */
- struct surface *target;
- /* TTY output id inherited by children (0 = none, use the old screen). */
- int tty;
- };
- /* User-mode virtual address layout (ring-3 processes). */
- #define USER_BASE 0x40000000 /* user program link/load address */
- #define USER_STACK_TOP 0x40200000 /* user stack top (grows down) */
- #define USER_STACK_PAGES 2 /* user stack size in 4 KB pages */
- /* Where sys_gfx maps a command's canvas back buffer (see sys_gfx.c). The
- * mapping is released by the reaper without freeing the canvas pages: the
- * gfx session owns those. */
- #define USER_GFX_BASE 0x50000000
- #define USER_GFX_RANGE 0x00400000 /* one 4 MB slot */
- /* Dynamically-sized process table (grown on demand; see process.c). */
- extern struct process *procs;
- extern volatile unsigned int current_pid;
- void process_init(void);
- int process_create(const char *name, void (*entry)(void));
- int process_create_arg(const char *name, void (*entry)(const char *),
- const char *arg);
- int process_create_ptr(const char *name, void (*entry)(void *), void *arg);
- /* Load an ELF image into a fresh address space and run it as a ring-3
- * process, with `arg` (may be NULL) as the first C parameter of _start.
- * Returns the pid, -1 when out of resources, or -2 when the image is not a
- * loadable ELF. */
- int process_create_user(const char *name, const void *image, unsigned int size,
- const char *arg, const char *cwd);
- /* Same, but with an explicit tty id (0 = inherit the caller's tty). */
- int process_create_user_tty(const char *name, const void *image,
- unsigned int size, const char *arg, const char *cwd,
- unsigned int tty);
- void process_set_screen(struct text_screen *screen);
- /* Render target override for the running process (0 = the screen). */
- struct surface *process_render_target(void);
- void process_set_render_target(struct surface *s);
- /* Map an MMIO range into the kernel's page directory and every live process
- * copy (and thus every process created later, which clones the kernel map).
- * Drivers that map their register window at command time must use this: a
- * process runs with its own page-directory copy, so paging_map_mmio() alone
- * would only be visible to the kernel bootstrap context. */
- void process_map_mmio_all(unsigned int phys_base, unsigned int size);
- void process_exit(void);
- void schedule(void);
- void process_ps(void);
- /* Fill *out with a snapshot of the index-th live process (slot order) for
- * the `top` command. Returns 1 when found, 0 at the end of the table. */
- int process_procinfo(unsigned int index, struct sys_procinfo *out);
- int process_kill(unsigned int pid);
- int process_is_alive(unsigned int pid);
- /* 1 while the process is in PROC_SLEEPING (the WM uses this to tell when it
- * is safe to reap another window's canvas). */
- int process_is_sleeping(unsigned int pid);
- void process_set_tty(unsigned int pid, int tty);
- void process_wait(unsigned int pid);
- /* Block the current process for `ms` milliseconds (yields the CPU). */
- void process_sleep_ms(unsigned int ms);
- #endif
|