process.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Preemptive round-robin multitasking for i586, ring-0 only. */
  2. #ifndef PROCESS_H
  3. #define PROCESS_H
  4. #define PROC_STACK_SIZE 0x1000 /* 4 KB per process (= 1 page) */
  5. /* Process stacks are allocated from the frame allocator (mm.c), i.e. above the
  6. * VGA shadow buffer. If that is unavailable (no E820 map) we fall back to a
  7. * small fixed pool below 1 MB so the system still boots with fewer processes. */
  8. #define PROC_FALLBACK_STACK_BASE 0x42000
  9. #define PROC_FALLBACK_STACK_MAX 8
  10. #define PROC_UNUSED 0
  11. #define PROC_READY 1
  12. #define PROC_RUNNING 2
  13. #define PROC_DEAD 3
  14. #define TIMESLICE_TICKS 20 /* context switch every 20 ms (PIT @ 1 kHz) */
  15. #define PROC_NAME_LEN 12
  16. struct text_screen; /* forward decl (see screen.h) */
  17. struct process {
  18. unsigned int esp;
  19. unsigned int state;
  20. unsigned int pid;
  21. char name[PROC_NAME_LEN];
  22. struct text_screen *screen; /* output target for io_putchar & co. */
  23. unsigned int stack_base; /* page to free on exit, or 0 (bootstrap/fallback) */
  24. };
  25. /* Dynamically-sized process table (grown on demand; see process.c). */
  26. extern struct process *procs;
  27. extern volatile unsigned int current_pid;
  28. void process_init(void);
  29. int process_create(const char *name, void (*entry)(void));
  30. int process_create_arg(const char *name, void (*entry)(const char *),
  31. const char *arg);
  32. int process_create_ptr(const char *name, void (*entry)(void *), void *arg);
  33. void process_set_screen(struct text_screen *screen);
  34. void process_exit(void);
  35. void schedule(void);
  36. void process_ps(void);
  37. int process_kill(unsigned int pid);
  38. int process_is_alive(unsigned int pid);
  39. void process_wait(unsigned int pid);
  40. #endif