12 #define RLIMIT_STACK_VAL 0x800000
14 #define TASK_KERNEL 0x1
15 #define TASK_NOSCHED 0x2
18 * memory map for processes
19 * 0xFFFFFFFF8000000 and up, kernel, can copy kernel pml4 entries
20 * program load at 4 MB
21 * stack at 128 TB = 8000 0000 0000 (and down)
22 * mmaps at 127 TB = 7F00 0000 0000 (and down)
23 * heap at 96 TB = 6000 0000 0000 (and up)
25 * heap after program load...
26 * program at 4 MB = 40 0000
29 /* so, to create a process,
30 * allocate 2 MB for stack,
31 * allocate whatever is needed for the code
32 * load in the code to the code base
33 * set up the registers
34 * set up the stack for the iretq or sysret
35 * iretq or sysret to start the task
59 uint64_t kernel_stack;
62 __attribute__((aligned(16))) uint8_t fpuenv[512];
63 } __attribute__((packed));
67 /* user or kernel process */
69 /* needs re-scheduled */
70 #define TM_SCHEDULE 0x2
72 #define TM_SYSCALL 0x4
74 #define TM_INTERRUPTED 0x8
76 #define TM_RUNNABLE 0x10
82 /* todo just use a user or kernel process, maybe a flag */
83 int pl; /* privilege level, 0 for kernel, 3 for users */
84 uint64_t flags; /* bit flags */
87 vaddr_t kstack; /* pointer to the kernel stack */
89 vaddr_t usp; /* user stack pointer */
91 struct process *next, *prev; /* scheduling */
93 /* sleep should probably be a struct timespec */
94 uint64_t sleep; /* don't need to sleep for 64 bits of ticks */
96 int status; /* return status from main/exit */
97 unsigned int quantum; /* how many more ticks */
99 // struct sigaction_t sigaction[NUM_SIGNALS];
100 // uint64_t signal_pending;
101 int (*main)(int ac, char **av);
104 uint64_t getrflags(); /* assembly */
107 pid_t create_task(struct process *task, void (*main)(), uint64_t rflags, uint64_t pagedir, uint64_t flags);
108 struct process *new_task(void (*entry)(), uint64_t rflags, uint64_t pagedir, uint64_t flags);
110 void sleep(uint32_t ticks);
114 void preempt(); // Switch task frontend
115 void switch_task(struct registers *old, struct registers *new);
116 void switch_task_iret(struct registers *old, struct registers *new);
119 void usermodetrampoline(void (*main)(), uint64_t rflags);