process.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 PROC_SLEEPING 4
  15. #define TIMESLICE_TICKS 20 /* context switch every 20 ms (PIT @ 1 kHz) */
  16. #define PROC_NAME_LEN 12
  17. struct text_screen; /* forward decl (see screen.h) */
  18. struct process {
  19. unsigned int esp;
  20. unsigned int state;
  21. unsigned int pid;
  22. char name[PROC_NAME_LEN];
  23. struct text_screen *screen; /* output target for io_putchar & co. */
  24. unsigned int stack_base; /* page to free on exit, or 0 (bootstrap/fallback) */
  25. unsigned int cr3; /* physical address of this process's page dir */
  26. unsigned int kstack_top; /* ring-0 stack top (for TSS esp0) */
  27. unsigned int wake_ms; /* tick deadline when PROC_SLEEPING */
  28. };
  29. /* User-mode virtual address layout (ring-3 processes). */
  30. #define USER_BASE 0x40000000 /* user program link/load address */
  31. #define USER_STACK_TOP 0x40200000 /* user stack top (grows down) */
  32. #define USER_STACK_PAGES 2 /* user stack size in 4 KB pages */
  33. /* Dynamically-sized process table (grown on demand; see process.c). */
  34. extern struct process *procs;
  35. extern volatile unsigned int current_pid;
  36. void process_init(void);
  37. int process_create(const char *name, void (*entry)(void));
  38. int process_create_arg(const char *name, void (*entry)(const char *),
  39. const char *arg);
  40. int process_create_ptr(const char *name, void (*entry)(void *), void *arg);
  41. /* Load an ELF image into a fresh address space and run it as a ring-3
  42. * process. Returns the pid, or -1 on error. */
  43. int process_create_user(const char *name, const void *image, unsigned int size);
  44. void process_set_screen(struct text_screen *screen);
  45. void process_exit(void);
  46. void schedule(void);
  47. void process_ps(void);
  48. int process_kill(unsigned int pid);
  49. int process_is_alive(unsigned int pid);
  50. void process_wait(unsigned int pid);
  51. /* Block the current process for `ms` milliseconds (yields the CPU). */
  52. void process_sleep_ms(unsigned int ms);
  53. #endif